Я пытаюсь использовать свой собственный набор данных для обучения сети GAN. У меня проблемы с загрузкой собственного набора данных в формате .jpg. У меня есть существующие наборы данных jpg, которые работают, я не вижу разницы в кодировке jpg между рабочим и не рабочим наборами данных.
Фотографии преобразуются с помощью машины Windows и переименовываются в 001.jpg 002.jpg и т. Д. Для обучения я использую машину Linux.
Программа python Я использую следующий код для загрузки и преобразования изображений в тензоры:
def _image_batch(image_paths,
batch_size,
load_size=286,
crop_size=256,
channels=3,
prefetch_batch=2,
drop_remainder=True,
num_threads=16,
shuffle=True,
buffer_size=4096,
repeat=-1):
def _parse_func(path):
img = tf.read_file(path)
img = tf.image.decode_jpeg(img, channels=channels)
img = tf.image.random_flip_left_right(img)
img = tf.image.resize_images(img, [load_size, load_size])
img = (img - tf.reduce_min(img)) / (tf.reduce_max(img) - tf.reduce_min(img))
img = tf.random_crop(img, [crop_size, crop_size, channels])
img = img * 2 - 1
return img
Полная ошибка:
Traceback (most recent call last):
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 510, in _apply_op_helper
preferred_dtype=default_dtype)
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1040, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 883, in _TensorTensorConversionFunction
(dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype string for Tensor with dtype float32: 'Tensor("arg0:0", shape=(), dtype=float32)'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "train.py", line 112, in <module>
a_test_pool = data.ImageData(sess, a_test_img_paths, batch_size, load_size=load_size, crop_size=crop_size)
File "/mnt/storage/scratch/ag17634/CycleGAN-Tensorflow-Pytorch/data.py", line 35, in __init__
repeat)
File "/mnt/storage/scratch/ag17634/CycleGAN-Tensorflow-Pytorch/data.py", line 68, in _image_batch
dataset = dataset.map(_parse_func, num_parallel_calls=num_threads)
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 840, in map
return ParallelMapDataset(self, map_func, num_parallel_calls)
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1857, in __init__
super(ParallelMapDataset, self).__init__(input_dataset, map_func)
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1826, in __init__
self._map_func.add_to_graph(ops.get_default_graph())
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 488, in add_to_graph
self._create_definition_if_needed()
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 321, in _create_definition_if_needed
self._create_definition_if_needed_impl()
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 338, in _create_definition_if_needed_impl
outputs = self._func(*inputs)
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1791, in tf_map_func
ret = map_func(nested_args)
File "/mnt/storage/scratch/ag17634/CycleGAN-Tensorflow-Pytorch/data.py", line 57, in _parse_func
img = tf.read_file(path)
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/ops/gen_io_ops.py", line 527, in read_file
"ReadFile", filename=filename, name=name)
File "/mnt/storage/software/languages/anaconda/Anaconda3-5.2.0-tflow-1.7/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 533, in _apply_op_helper
(prefix, dtypes.as_dtype(input_arg.type).name))
TypeError: Input 'filename' of 'ReadFile' Op has type float32 that does not match expected type of string.