我正在研究一个深度学习问题,该问题要求我有一个深度学习模型,该模型具有输入图像和输出另一个图像的功能。现在,输入和输出图像的尺寸不同,因此,我不能使用自动编码器。我已经尝试构建一个非常简单的卷积神经网络,该网络具有最终的输出密集层,该输出密集层具有“单位”自变量,即输出图像的宽度和高度相乘。但是,我下面附加的该网络没有成功。我的问题是:
谢谢!
以下是我已经尝试过的CNN模型的摘要:
conv2d_1(Conv2D)(无,26、877、32)544
activation_1(激活)(无,26、877、32)0
max_pooling2d_1(MaxPooling2(None,13,438,32)0
conv2d_2(Conv2D)(无,12、437、16)2064
activation_2(激活)(无,12、437、16)0
max_pooling2d_2(MaxPooling2(None,6,218,16)0
conv2d_3(Conv2D)(无,5、217、8)520
activation_3(激活)(无,5、217、8)0
max_pooling2d_3(MaxPooling2(None,2,108,8)0
activation_4(激活)(无,2、108、8)0
flatten_1(扁平)(无,1728)0
dropout_1(退出)(无,1728)0
dense_1(Dense)(None,19316)33397364
================================================ ================== 参数总计:33,400,492 可训练的参数:33,400,492 不可训练的参数:0
def generator(data_arr, batch_size = 10):
num = len(data_arr)
if num % batch_size != 0 :
num = int(num/batch_size)
# Loop forever so the generator never terminates
while True:
for offset in range(0, num, batch_size):
batch_samples = (data_arr[offset:offset+batch_size])
samples = []
labels = []
for batch_sample in batch_samples:
samples.append(batch_sample[0])
labels.append((np.array(batch_sample[1].flatten)).transpose())
X_ = np.array(samples)
Y_ = np.array(labels)
X_ = X_[:, :, :, newaxis]
yield (X_, Y_)
# compile and train the model using the generator function
train_generator = generator(training_data, batch_size = 10)
validation_generator = generator(val_data, batch_size = 10)
run_opts = tf.RunOptions(report_tensor_allocations_upon_oom = True)
model = Sequential()
model.add(Conv2D(32, (4, 4), strides=(2, 2), input_shape = (55, 1756,
1)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Conv2D(16, (2, 2)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Conv2D(8, (2, 2)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Activation('softmax'))
model.add(Flatten())
model.add(Dropout(0.3))
model.add(Dense(19316))
model.compile(loss = 'categorical_crossentropy',
optimizer = 'adam',
metrics = ['accuracy'],
options = run_opts)
model.summary()
batch_size = 20
nb_epoch = 6
model.fit_generator(train_generator,
steps_per_epoch = len(training_data) ,
epochs = nb_epoch,
validation_data = validation_generator,
validation_steps = len(val_data))