python – 为图像塑造Tensorflow / TFLearn输入/输出的问题

为了更多地了解深度学习和计算机视觉,我正在研究一个在道路上进行车道检测的项目.我正在使用TFLearn作为Tensorflow的包装器.

背景

训练输入是道路的图像(每个图像表示为50×50像素的2D阵列,每个元素是0.0到1.0的亮度值).

训练输出的形状相同(50×50阵列),但代表标记的车道区域.实质上,非道路像素为0,道路像素为1.

这不是固定大小的图像分类问题,而是从图片中检测道路与非道路像素的问题.

问题

我无法以TFLearn / Tensorflow接受的方式成功塑造我的输入/输出,我不知道为什么.这是我的示例代码:

# X = An array of training inputs (of shape (50 x 50)).
# Y = An array of training outputs (of shape (50 x 50)).

# "None" equals the number of samples in my training set, 50 represents
# the size of the 2D image array, and 1 represents the single channel
# (grayscale) of the image.
network = input_data(shape=[None, 50, 50, 1])

network = conv_2d(network, 50, 50, activation='relu')

# Does the 50 argument represent the output shape? Should this be 2500?
network = fully_connected(network, 50, activation='softmax')

network = regression(network, optimizer='adam', loss='categorical_crossentropy', learning_rate=0.001)

model = tflearn.DNN(network, tensorboard_verbose=1)

model.fit(X, Y, n_epoch=10, shuffle=True, validation_set=(X, Y), show_metric=True, batch_size=1)

我收到的错误是在model.fit调用上,错误:

ValueError:无法为Tensor u’InputData / X:0’提供形状值(1,50,50),其形状为'(?,50,50,1)’

我已经尝试将样本输入/输出数组缩减为1D向量(长度为2500),但这会导致其他错误.

我对如何塑造这一切有点迷茫,任何帮助都将不胜感激!

最佳答案 看看tensorflow的imageflow包装器,它将包含多个图像的numpy数组转换为.tfrecords文件,这是使用tensorflow
https://github.com/HamedMP/ImageFlow的建议格式.

你必须使用它来安装它

$pip install imageflow

假设包含一些’k’图像的numpy数组是k_images,相应的k标签(one-hot-encoded)存储在k_labels中,然后创建名为’tfr_file.tfrecords’的.tfrecords文件就像写行一样简单

imageflow.convert_images(k_images, k_labels, 'tfr_file')

或者,Google的Inception模型包含一个代码,用于读取文件夹中的图像,假设每个文件夹代表一个标签https://github.com/tensorflow/models/blob/master/inception/inception/data/build_image_data.py

点赞