【发布时间】:2018-03-21 21:03:22
【问题描述】:
我正在调整 this tutorial here,以便我可以在自己的一组图像中训练一个 ConvNet。
所以我创建了这个函数来尝试获取批次,尽管它还没有创建批次:
def training_batch(batch_size):
images = trainpaths
for i in range(len(images)):
# converting the path to an image
image = mpimg.imread(images[i])
images[i] = image
# Create batches
X, Y = images, trainlabels
return X, Y
这里调用了这个函数:
def optimize(num_iterations):
global total_iterations
for i in range(total_iterations,
total_iterations + num_iterations):
# Get a batch of training examples.
# x_batch now holds a batch of images and
# y_true_batch are the true labels for those images.
x_batch, y_true_batch = training_batch(train_batch_size)
# Put the batch into a dict with the proper names
# for placeholder variables in the TensorFlow graph.
feed_dict_train = {x: x_batch,
y_true: y_true_batch}
# Run the optimizer using this batch of training data.
# TensorFlow assigns the variables in feed_dict_train
# to the placeholder variables and then runs the optimizer.
session.run(optimizer, feed_dict=feed_dict_train)
(...)
如果我运行这个代码,我就会得到
Traceback (most recent call last):
File "scr.py", line 405, in <module>
optimize(1)
File "scr.py", line 379, in optimize session.run(optimizer, feed_dict=feed_dict_train)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 905, in run run_metadata_ptr)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1116, in _run str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (2034, 218, 178, 3) for Tensor u'x:0', which has shape '(?, 116412)'
有人可以说明如何解决这个问题吗?
【问题讨论】:
标签: python dictionary tensorflow machine-learning conv-neural-network