我必须用生成器和鉴别器训练 GAN 网络。我的发电机网络如下。
def Generator(image_shape=(512,512,3):
inputs = Input(image_shape)
# 5 convolution Layers
# 5 Deconvolution Layers along with concatenation
# output shape is (512,512,3)
model=Model(inputs=inputs,outputs=outputs, name='Generator')
return model, output
Run Code Online (Sandbox Code Playgroud)
我的鉴别器网络如下。鉴别器网络的第一步是我必须将鉴别器的输入与生成器的输出连接起来。
def Discriminator(Generator_output, image_shape=(512,512,3)):
inputs=Input(image_shape)
concatenated_input=concatenate([Generator_output, inputs], axis=-1)
# Now start applying Convolution Layers on concatenated_input
# Deconvolution Layers
return Model(inputs=inputs,outputs=outputs, name='Discriminator')
Run Code Online (Sandbox Code Playgroud)
启动架构
G, Generator_output=Generator(image_shape=(512,512,3))
G.summary
D=Discriminator(Generator_output, image_shape=(512,512,3))
D.summary()
Run Code Online (Sandbox Code Playgroud)
我的问题是当我传递concatenated_input到convolution图层时,它会出现以下错误。
Graph disconnected: cannot obtain value for tensor Tensor("input_1:0", shape=(?, 512, 512, 3), dtype=float32) at layer …Run Code Online (Sandbox Code Playgroud) python-3.x deep-learning keras tensorflow generative-adversarial-network
使用 keras,我必须训练一个模型来预测图像属于 0 类还是 1 类。我对二进制和 categorical_cross_entropy 感到困惑。我已经搜索过了,但我仍然很困惑。有人提到,当我们尝试预测多类时,我们仅使用分类交叉熵,并且我们应该为此使用 one-hot-encoder 向量。因此,这意味着当我们使用binary_cross_entrpoy进行训练时,我们不需要任何one-hot编码的向量标签。有些人建议将 one_hot 向量表示为 [0. 1.](如果类别为 1)或 [1. 0.](如果类别为 0)用于 binary_cross_entropy。我正在使用带有分类交叉熵的热编码器 [0 1] 或 [1 0]。我的最后一层是
model.add(Dense(num_classes, activation='softmax'))
# Compile model
model.compile(loss='categorical_crossentropy',
optimizer='adadelta',
metrics=['accuracy'])
Run Code Online (Sandbox Code Playgroud) 请参阅此C ++代码,我尝试在python中进行更改以执行完全相同的操作,但我陷入for循环中以找到Aspect_ratio。我没有得到任何线索,以获得最小和最大 宽度和高度的RotatedRect在python作为替代品RotatedRect的C ++中Python是cv2.boxPoints
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('C:/Users/Zeeesh/Desktop/1.jpg', cv2.IMREAD_GRAYSCALE)
ret,thresh = cv2.threshold(img,200,255,0)
img1,contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
out = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
for contour in contours:
rect = cv2.minAreaRect(contour)
(x, y), (width, height), angle = rect
aspect_ratio = min(width, height) / max(width, height)
thresh1 = 0.2
if (aspect_ratio > thresh1):
print('Straight Line')
for pt in contour:
cv2.drawContours(out, [pt], …Run Code Online (Sandbox Code Playgroud)