【发布时间】:2017-06-28 12:42:49
【问题描述】:
我是 TF 的菜鸟,所以放轻松。
我必须从带有标签的目录中的一堆图像中训练一个简单的 CNN。看了很多遍后,我编写了这段准备 TF 输入管道的代码,并且能够打印图像数组。
image_list, label_list = load_dataset()
imagesq = ops.convert_to_tensor(image_list, dtype=dtypes.string)
labelsq = ops.convert_to_tensor(label_list, dtype=dtypes.int32)
# Makes an input queue
input_q = tf.train.slice_input_producer([imagesq, labelsq],
shuffle=True)
file_content = tf.read_file(input_q[0])
train_image = tf.image.decode_png(file_content,channels=3)
train_label = input_q[1]
train_image.set_shape([120,120,3])
# collect batches of images before processing
train_image_batch, train_label_batch = tf.train.batch(
[train_image, train_label],
batch_size=5
# ,num_threads=1
)
with tf.Session() as sess:
# initialize the variables
sess.run(tf.global_variables_initializer())
# initialize the queue threads to start to shovel data
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
# print "from the train set:"
for i in range(len(image_list)):
print sess.run(train_image_batch)
# sess.run(train_image)
# sess.run(train_label)
# classifier.fit(input_fn=lambda: (train_image, train_label),
# steps=100,
# monitors=[logging_hook])
# stop our queue threads and properly close the session
coord.request_stop()
coord.join(threads)
sess.close()
但是查看 TF 文档中给出的 MNIST 示例,我看到他们使用 cnn_model_fn 和 Estimator 类。
我已经定义了自己的 cnn_model_fn,并希望将两者结合起来。请帮助我了解如何继续前进。此代码不起作用
classifier = learn.Estimator(model_fn=cnn_model_fn, model_dir='./test_model')
classifier.fit(input_fn=lambda: (train_image, train_label),
steps=100,
monitors=[logging_hook])
似乎只有在会话运行时才填充管道,否则它是空的并且它给出一个 ValueError '输入图和层图不一样'
请帮帮我。
【问题讨论】:
标签: python tensorflow conv-neural-network