[英]How to use list of images as input of CNN in TensorFlow?
I'm a newbie of TensorFlow, I have a problem when using list as inputs for CNN. 我是TensorFlow的新手,使用列表作为CNN的输入时遇到问题。
Let say that I have 4 list: 假设我有4个清单:
TrainingImage
: This is a list that has all images that I want to train, each image I is BGR channels,, so i put image I to this list by using TrainingImage.append(I)
. TrainingImage
:这是一个列表,其中包含我要训练的所有图像,每个图像都是BGR通道,因此我使用TrainingImage.append(I)
将图像I放入此列表。 TrainingLabel
: This is a list for labeling image in TrainingImage
, each row is a one-hot vector. TrainingLabel
:这是在TrainingImage
标记图像的列表,每一行都是一个热向量。 For example if I have 3 object (1, 2, 3), each object has 2 images (which mean TrainingImage
has 3 x 2 = 6 images), then I have a list of label like: 1, 0, 0; TrainingImage
有3 x 2 = 6张图像),那么我就拥有一个标签列表,例如:1、0、0; 1, 0, 0; TestingImage
: List that has all images for test, similar to TrainingImage
but fewer images. TestingImage
:具有所有要测试图像的列表,类似于TrainingImage
但图像较少。 TestingLabel
: List that has all label of TestingImage
TestingLabel
:具有所有TestingImage
标签的TestingImage
I don't know how to use it as inputd for CNN in TensorFlow. 我不知道如何在TensorFlow中将其用作CNN的输入。 I'm using the following code, each image has size 68 x 68 x 3, I have 17 object, each object I have 64 images for training, 16 images for testing.
我正在使用以下代码,每个图像的尺寸为68 x 68 x 3,我有17个对象,每个对象我有64个用于训练的图像,16个用于测试的图像。
with tf.Session() as sess:
与tf.Session()作为sess:
data_initializer = tf.placeholder(tf.float32, (1088, 68, 68, 3)) label_initializer = tf.placeholder(tf.float32, (1088, 17)) input_data = tf.Variable(data_initializer, trainable=False, collections=[]) input_labels = tf.Variable(label_initializer, trainable=False, collections=[]) sess.run(input_data.initializer, feed_dict={data_initializer: TrainingImage}) sess.run(input_labels.initializer, feed_dict={label_initializer: TrainingLabel})
So now input_data
and input_labels
is my new input for CNN but I'm not sure this is a right way? 因此,现在
input_data
和input_labels
是CNN的新输入,但是我不确定这是正确的方法吗? I'm using those above code by following this TensorFlow instruction https://www.tensorflow.org/programmers_guide/reading_data#preloaded_data , treat 4 lists as variables. 我通过遵循以下TensorFlow指令https://www.tensorflow.org/programmers_guide/reading_data#preloaded_data使用上述代码,将4个列表视为变量。
Yeah, that'll work. 是的,那可以。 May I recommend that instead of
我可以建议代替
data_initializer = tf.placeholder(tf.float32,(1088, 68, 68, 3))
you use 你用
data_initializer = tf.placeholder(tf.float32,(None, 68, 68, 3))
This will allow you to send in different amounts of images instead of always having to send in 1088 images. 这样您就可以发送不同数量的图像,而不必总是发送1088张图像。 At some point you way want to process just 1 image.
在某些时候,您只希望处理1张图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.