Tflearn,AxlexNet,ValueError:无法为Tensor u'InputData / X:0'提供形状值(64,277,277,3),其形状为'(?,227,227,3)'

时间:2016-12-13 12:45:28

标签: python tensorflow tflearn

我试图将示例AlexNet(https://github.com/tflearn/tflearn/blob/master/examples/images/alexnet.py)与我自己的数据一起使用,但是我收到以下错误:

ind_active(1/0)

我正在使用cv2来读取图像并将它们调整为277乘277像素,然后将所有图像存储在阵列X中,其形状为[146847,277,277,3]。 标签存储在多个csv文件中,并被读入数组Y,形状为[146847,5]。每个标签有5个不同的类,范围从0到1,分为0.2步。

网络代码如下:

python alex_net.py 
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally
^[I tensorflow/core/common_runtime/gpu/gpu_device.cc:951] Found device 0 with properties: 
name: GeForce GTX TITAN X
major: 5 minor: 2 memoryClockRate (GHz) 1.076
pciBusID 0000:05:00.0
Total memory: 11.92GiB
Free memory: 11.81GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:972] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX TITAN X, pci bus id: 0000:05:00.0)
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX TITAN X, pci bus id: 0000:05:00.0)
---------------------------------
Run id: alexnet_oxflowers17
Log directory: /tmp/tflearn_logs/
---------------------------------
Training samples: 132162
Validation samples: 14685
--
--
Traceback (most recent call last):
  File "alex_net.py", line 114, in <module>
    snapshot_epoch=False, run_id='alexnet_oxflowers17')
  File "/home/psxts3/.virtualenv/lib/python2.7/site-packages/tflearn/models/dnn.py", line 188, in fit
    run_id=run_id)
  File "/home/psxts3/.virtualenv/lib/python2.7/site-packages/tflearn/helpers/trainer.py", line 277, in fit
    show_metric)
  File "/home/psxts3/.virtualenv/lib/python2.7/site-packages/tflearn/helpers/trainer.py", line 684, in _train
    feed_batch)
  File "/home/psxts3/.virtualenv/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 717, in run
    run_metadata_ptr)
  File "/home/psxts3/.virtualenv/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 894, in _run
    % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (64, 277, 277, 3) for Tensor u'InputData/X:0', which has shape '(?, 227, 227, 3)'

其中num_classes = 5。

net = input_data(shape=[None, 227, 227, 3])
net = conv_2d(net, 96, 11, strides=4, activation='relu')
net = max_pool_2d(net, 3, strides=2)
net = local_response_normalization(net)
net = conv_2d(net, 256, 5, activation='relu')
net = max_pool_2d(net, 3, strides=2)
net = local_response_normalization(net)
net = conv_2d(net, 384, 3, activation='relu')
net = conv_2d(net, 384, 3, activation='relu')
net = conv_2d(net, 256, 3, activation='relu')
net = max_pool_2d(net, 3, strides=2)
net = local_response_normalization(net)
net = fully_connected(net, 4096, activation='tanh')
net = dropout(net, 0.5)
net = fully_connected(net, 4096, activation='tanh')
net = dropout(net, 0.5)
net = fully_connected(net, num_classes, activation='softmax')
net = regression(net, optimizer='momentum', loss='categorical_crossentropy', learning_rate=0.001)

如有任何进一步的信息,请询问。

1 个答案:

答案 0 :(得分:2)

正如nessuno在第一条评论中所说,你正在向图表中输入错误尺寸的图像。将第一行更改为以下内容。

net = input_data(shape=[None, 277, 277, 3])