Tflearn, AxlexNet, ValueError: Cannot feed value of shape (64, 277, 277, 3) for Tensor u'InputData/X:0', which has shape '(?, 227, 227, 3)'

Tflearn, AxlexNet, ValueError: Cannot feed value of shape (64, 277, 277, 3) for Tensor u'InputData/X:0', which has shape '(?, 227, 227, 3)'

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

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)'

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

网络代码如下:

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)

其中 num_classes = 5.

model = tflearn.DNN(net, checkpoint_path='model_alexnet',
                max_checkpoints=1, tensorboard_verbose=2)
model.fit(X, Y, n_epoch=1000, validation_set=0.1, shuffle=True,
      show_metric=True, batch_size=64, snapshot_step=200,
      snapshot_epoch=False, run_id='alexnet_oxflowers17')

任何进一步的信息需要请询问。

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

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