我有500个RGB彩色图像标签(200x300像素)未标记,用于无监督学习(CNN,GAN,自动编码器)。 我想将图像集导入到tensorflow,而不是MNIST示例。 我需要将它们转换为CSV文件吗?
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("./", one_hot=True)
答案 0 :(得分:0)
这是我训练GAN的代码的一部分。像这样读取文件。这是做到这一点的一种方法。
filenames = tf.train.string_input_producer(
tf.train.match_filenames_once("D:/TensorFlow/resizedimages/*.png"))
参考代码是这个。
def train():
filenames = tf.train.string_input_producer(
tf.train.match_filenames_once("D:/TensorFlow/resizedimages/*.png"))
reader = tf.WholeFileReader()
_, input = reader.read(filenames)
input = tf.image.decode_png(input, channels=3)
input.set_shape([299, 299, 3])
batch = tf.train.batch([input],
batch_size=30)
init = (tf.global_variables_initializer(), tf.local_variables_initializer())
with tf.Session() as sess:
sess.run(init)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
train_writer = tf.summary.FileWriter('D:/TensorFlow/logs/1/train', sess.graph)
tf.summary.image("Image", GeneratedImage)
merge = tf.summary.merge_all()
for it in range(100):
_, X_batch = sess.run([input,batch])
summary,_ = sess.run([merge,D_optimizer], feed_dict={Z : samplefromuniformdistribution(20,100), X: X_batch, keep_prob: keep_prob_value})
summary,_ = sess.run([merge,G_optimizer],feed_dict={ Z : samplefromuniformdistribution(20,100), X: X_batch, keep_prob: keep_prob_value})
train_writer.add_summary(summary, it)
train_writer.flush()
train_writer.close()
coord.request_stop()
coord.join(threads)