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

标签 python machine-learning computer-vision neural-network tensorflow

为了了解有关深度学习和计算机视觉的更多信息,我正在从事一个在道路上执行车道检测的项目。我将 TFLearn 用作 Tensorflow 的包装器。

背景

训练输入是道路图像(每个图像表示为一个 50x50 像素的二维数组,每个元素都是一个从 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:无法为形状为“(?, 50, 50, 1)”的 Tensor u'InputData/X:0' 提供形状 (1, 50, 50) 的值

我尝试将示例输入/输出数组减少为一维向量(长度为 2500),但这会导致其他错误。

我对如何塑造这一切有点迷茫,非常感谢任何帮助!

最佳答案

查看 tensorflow 的图像流包装器,它将包含多个图像的 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

关于python - 为图像塑造 Tensorflow/TFLearn 输入/输出的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40064422/

相关文章:

python - ImportError : No module named PyQt4. QtCore

python - 如何将我的 epd python 作为我在 ubuntu 中的默认 python?

python - Tensorflow - tf.nn.weighted_cross_entropy_with_logits - logits 和目标必须具有相同的形状

python - 分类数据的随机森林分类器?

python - 在 OpenCV python 中使用 seamlessClone 生成具有 "ghost"个对象的图像

python - 如何将矩形拟合到 python 中的图像并获取它们的坐标

python - 有没有办法在类内的装饰器中引用实例?

python - Django React axios 发布请求 : how to get csrftoken cookie?

machine-learning - 需要陷入神经网络的局部最优

python - 从像素坐标计算以厘米为单位的 x 和 y 坐标