【问题标题】:Loading other images into tensorflow, apart from MNIST将其他图像加载到张量流中,除了 MNIST
【发布时间】:2023-03-28 18:44:01
【问题描述】:

我对使用 tensorflow 应用卷积神经网络很感兴趣。但是,我看到的唯一教程是加载 MNIST 数据集。我尝试复制那里完成的程序并阅读互联网上的大量教程,但它不起作用。到目前为止,这是我的代码

import tensorflow as tf
import os
import numpy as np

filename = os.getcwd() + '/sample_images/*.png'
filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once(filename))

image_reader = tf.WholeFileReader()

_, image_file = image_reader.read(filename_queue)


image = tf.image.decode_png(image_file, 3)
image = tf.image.rgb_to_grayscale(image, name=None)
image = tf.image.resize_images(image, 28, 28, method=0, align_corners=False)

data = []
with tf.Session() as sess:
    tf.initialize_all_variables().run()

    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)

    image_tensor = sess.run([image])
    data.append(image_tensor)
    #print(image_tensor)
    coord.request_stop()
    coord.join(threads)

xx = np.asarray(data)
print xx[0].shape

基本上,我想做以下事情:- - 从带有名称的文件夹中加载图像

  • 将每个图像的大小调整为 28*28

  • 改成灰度

  • 将其转换为张量并将其添加到训练集

  • 创建它的目标(从它的标签并将其添加到一个 numpy 数组)

  • 对文件夹中的所有图像重复

完成后,将数据集和目标传递给 tensorflow RNN

我们将不胜感激所有帮助

【问题讨论】:

    标签: machine-learning tensorflow skflow


    【解决方案1】:

    看看TensorVisiongeneric_input_producer。输入函数接受图像列表并返回代表一批图像的张量。预处理,包括调整大小也在其中完成。

    【讨论】:

      猜你喜欢
      • 2018-01-04
      • 2017-12-15
      • 2017-11-09
      • 2017-10-29
      • 2018-10-07
      • 2020-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多