你好,正在学习tensoflow和numpy。我正在尝试创建CNN图像分类模型。在
我的图像尺寸是28X28
这是我的模型:
MODEL_NAME = 'ComputerVision-{}-{}.model'.format(LR, '6conv-basic') # 6conv layer
import tensorflow as tf
tf.reset_default_graph()
convnet = input_data(shape=[None, IMG_SIZE, IMG_SIZE, 1], name='input')
# layer
convnet = conv_2d(convnet, 28, 5, activation='relu')
convnet = max_pool_2d(convnet, 5)
# layer
convnet = conv_2d(convnet, (56, 5, activation='relu')
convnet = max_pool_2d(convnet, 5)
#layer
convnet = conv_2d(convnet, 112, 5, activation='relu')
convnet = max_pool_2d(convnet, 5)
# layer
convnet = conv_2d(convnet, 56, 5, activation='relu')
convnet = max_pool_2d(convnet, 5)
#layer
convnet = conv_2d(convnet, 28, 5, activation='relu')
convnet = max_pool_2d(convnet, 5)
#dense layer
convnet = fully_connected(convnet, 784, activation='relu')
convnet = dropout(convnet, 0.8)
convnet = fully_connected(convnet, 2, activation='softmax')
convnet = regression(convnet, optimizer='adam', learning_rate=LR, loss='categorical_crossentropy', name='targets')
#my neural network model
model = tflearn.DNN(convnet, tensorboard_dir='log')
# train and test set
train = train_data[:-500]#my train data
test = train_data[-500:]
X = np.array([i[0] for i in train]).reshape(-1,IMG_SIZE,IMG_SIZE,1)
Y = [i[1] for i in train]
test_x = np.array([i[0] for i in test]).reshape(-1,IMG_SIZE,IMG_SIZE,1)
test_y = [i[1] for i in test]
model.fit({'input': X}, {'targets': Y}, n_epoch=10,
validation_set=({'input': test_x}, {'targets': test_y}), snapshot_step=200,show_metric=True,run_id=MODEL_NAME)
当我试图训练我的模型时,我遇到了一个错误:
当使用
tflearn
调用model.fit()
方法时,属性validation_set
中的条目必须是一个元组。尝试这样做:我希望它能起作用!
另外,请查看Deep Neural Network Model TFLearn docs here。在
相关问题 更多 >
编程相关推荐