TypeError:类型为' Image'的对象没有len()

时间:2017-03-20 13:07:18

标签: python-3.5 theano conv-neural-network lasagne

我正在编写一个程序来训练一个小天鹅网,将灰度图像着色为CIELab图像。以下是我的代码:

with open('mypicklegrey.pickle','rb') as fgrey:
   X_train = pickle.load(fgrey)
   print ('data_grey')



with open('mypicklelab.pickle','rb') as flab:
   Y_train = pickle.load(flab)
   print ('data_lab')

net1 = NeuralNet(
layers=[('input', layers.InputLayer),
        ('conv2d1', layers.Conv2DLayer),
        ('maxpool1', layers.MaxPool2DLayer),
        ('conv2d2', layers.Conv2DLayer),
        ('maxpool2', layers.MaxPool2DLayer),
        ('dropout1', layers.DropoutLayer),
        ('dense', layers.DenseLayer),
        ('dropout2', layers.DropoutLayer),
        ('output', layers.DenseLayer),

        ],
# input layer
input_shape=(None, 1, 224,224),
# layer conv2d1
conv2d1_num_filters=32,
conv2d1_filter_size=(3, 3),
conv2d1_nonlinearity=lasagne.nonlinearities.rectify,
conv2d1_W=lasagne.init.GlorotUniform(),  
# layer maxpool1
maxpool1_pool_size=(2, 2),    
# layer conv2d2
conv2d2_num_filters=32,
conv2d2_filter_size=(3, 3),
conv2d2_nonlinearity=lasagne.nonlinearities.rectify,
# layer maxpool2
maxpool2_pool_size=(2, 2),
# dropout1
dropout1_p=0.5,  

# dense
dense_num_units=256,
dense_nonlinearity=lasagne.nonlinearities.rectify,    
# dropout2
dropout2_p=0.5,

# output
output_nonlinearity=lasagne.nonlinearities.softmax,
output_num_units=10,
# optimization method params
update=nesterov_momentum,
update_learning_rate=0.01,
update_momentum=0.9,
max_epochs=10,

verbose=1,
)

以上代码运行正常,但我在训练网时遇到错误。

nn = net1.fit(X_train, Y_train)

ERROR ------------第350行,在_check_good_input-> x_len = len(X) TypeError:类型为' Image'的对象没有len()

我是编程神经网络的新手,并没有真正得到这个错误的原因究竟是什么,在这一点上被卡住了。任何帮助深表感谢。提前谢谢!

0 个答案:

没有答案