在TensorFlow中,我正在从一组PNG文件进行训练,并希望应用数据增强。我已经成功地使用了
但是,当我尝试使用
以下是我的代码。我哪里做错了吗?frac应该是
失败并显示错误信息:
tf.image.random_flip_left_right()
。但是,当我尝试使用
tf.image.central_crop()
时出现错误。基本上,我想要从均匀分布(0.8,1.0]中获得central_fraction。以下是我的代码。我哪里做错了吗?frac应该是
tf.random_uniform()
吗?filename_queue = tf.train.string_input_producer( tf.train.match_filenames_once("./images/*.png"))
image_reader = tf.WholeFileReader() # Read an entire image file
_, image_file = image_reader.read(filename_queue)
image = tf.image.decode_png(image_file, channels=3, dtype=tf.uint8, name="PNGDecompressor")
image.set_shape([800,400,3])
frac = random.uniform(0.8,1.0)
image = tf.image.central_crop(image, central_fraction = frac) # THIS FAILS
# image = tf.image.central_crop(image, central_fraction = 0.8) # THIS WORKS
image = tf.image.resize_images(image, [256, 128])
image.set_shape([256,128,3])
image = tf.cast(image, tf.float32) * (1. / 255) - 0.5 # Convert from [0, 255] -> [-0.5, 0.5] floats.
image = tf.image.per_image_whitening(image)
image = tf.image.random_flip_left_right(image, seed=42)
# Start a new session to show example output.
with tf.Session() as sess:
tf.initialize_all_variables().run()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
t_image= sess.run([image])
[...]
coord.request_stop()
coord.join(threads)
失败并显示错误信息:
TypeError: Fetch argument 0.9832154064713503 has invalid type <class 'float'>, must be a string or Tensor. (Can not convert a float into a Tensor or Operation.)
import tensoflow as tf;print tf.__git_version__
?此外,提供一些数据中png的链接可能会有所帮助。 - Saurabh Saxena