4

要学习更多关于深度学习和计算机视觉的知识,我正在开发一个项目来执行道路上的车道检测。我使用TFLearn作为Tensorflow的包装。塑造Tensorflow/TFLearn输入/输出图像的问题

背景

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

训练输出形状相同(50x50阵列),但表示标记的车道面积。本质上,非道路像素为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: Cannot feed value of shape (1, 50, 50) for Tensor u'InputData/X:0', which has shape '(?, 50, 50, 1)'

我试图减少样品输入/输出阵列以一维向量(长度为2500),但会导致其他错误。

我有点失落,如何塑造这一切,任何帮助将不胜感激!

+0

听起来像人事问题 – boztalay

回答

1

查看张量流的图像流包装器,它将包含多个图像的numpy数组转换为.tfrecords文件,这是使用张量流https://github.com/HamedMP/ImageFlow的建议格式。

你必须使用

$ pip install imageflow 

假设含有一些数“k”图像的numpy的阵列是k_images安装它和相应的K标签(一个热编码)被存储在k_labels,然后创建一个。名为tfrecords文件“tfr_file.tfrecords”得到这么简单写入行

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

另外,谷歌的盗梦空间模型包含一个代码假设每个文件夹中的文件夹中读取的图像代表一个标签https://github.com/tensorflow/models/blob/master/inception/inception/data/build_image_data.py

+0

感谢您的答案。我知道你的这两个链接都有助于将图像序列化为.tfrecords格式,但我不确定这是如何帮助(或适合)训练模型的更大问题。如果我能够首先使用基本层基础结构(使用普通浮点数组),那么稍后我可以使用这些框架之一,对吧? –

1

错误指出您有张量形状冲突,其中一个大小为4,另一个大小为3.这是由于输入数据(X)不是形状[-1,50,50,1] 。这里所需要的只是将X重新塑造成正确的形状,然后才能进入您的网络。

# 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. 

X = tensorflow.reshape(X, shape[-1, 50, 50, 1]) 
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)