我使用tflearn成功建立了一个简单的CNN网络,用于(医学)图像分类。当我尝试将元数据添加到CNN时,我遇到了以下问题:ValueError:无法为形状为((1390,2)''的Tensor'TargetsData / Y:0'输入形状(96,2)的值。任何帮助表示赞赏:
#extract pictures (0 thru 4095), next two bytes for the selection, and the rest for metadata
X, Y, Z = train_data[:,0:4096],train_data[:,4096:4098], train_data[:,4098:]
X = X.reshape([-1,64,64,1])
network = input_data(shape=[None, 64, 64, 1])
mdnetwork = input_data(shape=[None, 100])
network = conv_2d(network, 30, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 30, 3, activation='relu')
network = conv_2d(network, 40, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 40, 3, activation='relu')
network = conv_2d(network, 40, 3, activation='relu')
network = conv_2d(network, 30, 3, activation='relu')
network = max_pool_2d(network, 2)
network = fully_connected(network, 100, activation='relu')
Zt= fully_connected(Z, 100, activation='relu')
network = merge([network,Zt], 'concat')
network = dropout(network, 0.5)
network = fully_connected(network, 50, activation='relu')
network = fully_connected(network, 2, activation='softmax')
# Train using classifier
network = regression(network, optimizer='adam',
loss='categorical_crossentropy',
learning_rate=0.001)
model = tflearn.DNN(network, tensorboard_verbose=3)
model.fit([np.array(X).reshape(-1, 64, 64, 1), np.array(Z).reshape(-1, 100)], Y, n_epoch=5, shuffle=True, validation_set=0,
show_metric=True, batch_size=96, run_id='my_cnn')
model.save('my_cnn.tflearn')
答案 0 :(得分:0)
很好,我可以在这里回答我的问题!无论如何,我在上面的代码中发现了问题。这是一个简单的错误。错误消息使我误入歧途。解决方法如下:替换此代码段
Zt= fully_connected(Z, 100, activation='relu')
network = merge([network,Zt], 'concat')
使用
network = merge([network, mdnetwork], 'concat')
感谢那些阅读我的要求的人。让我知道是否还有其他选择。