简体   繁体   English

自己的数据集ValueError:使用dtype float32的Tensor的Tensor转换请求了dtype字符串

[英]Own dataset ValueError: Tensor conversion requested dtype string for Tensor with dtype float32

I'm trying to use my own dataset to train a GAN network. 我正在尝试使用自己的数据集来训练GAN网络。 I'm having issues with loading my own dataset in .jpg format. 我在以.jpg格式加载自己的数据集时遇到问题。 I have existing jpg datasets that work, I can't see a difference in the jpg encoding between the working and not working datasets. 我已经可以使用现有的jpg数据集,但看不到有效数据集和无效数据集之间jpg编码的区别。

The photos are converted using a windows machine and renamed to 001.jpg 002.jpg etc. For training I'm using a linux machine. 照片是使用Windows机器转换的,并重命名为001.jpg 002.jpg等。为进行培训,我使用的是Linux机器。

The python program I'm using the following code to load and convert images to tensors: 我正在使用以下代码的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

The full error is: 完整的错误是:

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.

This sounds like a converting issue. 这听起来像一个转换问题。 I think you may have to call str(input) on the input you are passing as filename. 我认为您可能必须在作为文件名传递的输入上调用str(input)

I have got same error with you. 我有同样的错误。

I solve it: change the path name correctly. 我解决了:正确更改路径名。

I guess in your case, you should check you "path" name in codes 我想在您的情况下,您应该在代码中检查“路径”名称

img = tf.read_file(path)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:张量转换为具有 dtype float32 的张量请求 dtype float32_ref - ValueError: Tensor conversion requested dtype float32_ref for Tensor with dtype float32 使用dtype float32(lambda输入)的Tensor的Tensor转换请求dtype字符串 - Tensor conversion requested dtype string for Tensor with dtype float32 (lambda input) ValueError: Tensor 转换请求 dtype int32 for Tensor with dtype float32 - LSTM Implementation(tensorflow 2.0.0) - ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32 - LSTM Implementation( tensorflow 2.0.0) Tensor转换请求dtype float32的dtype float64 - Tensor conversion requested dtype float64 for Tensor with dtype float32 ValueError: Tensor(&quot;ExponentialDecay_4:0&quot;, shape=(), dtype=float32) - ValueError: Tensor("ExponentialDecay_4:0", shape=(), dtype=float32) 值错误:列名:<name> input_tensor dtype 必须是字符串或 integer。 数据类型:<dtype: 'float32'></dtype:></name> - ValueError: column_name: <Name> input_tensor dtype must be string or integer. dtype: <dtype: 'float32'> ValueError: column_name: input_tensor dtype 必须是字符串或 integer。 数据类型:<dtype: 'float32'></dtype:> - ValueError: column_name: input_tensor dtype must be string or integer. dtype: <dtype: 'float32'> Tensorflow 图像生成器通过 dtype=string 的张量而不是 dtype=float32 的张量来丢失 function - Tensorflow Image Generator passing Tensor with dtype=string instead of Tensor with dtype=float32 to loss function python - ValueError: Tensor Tensor(&quot;dense_2/Softmax:0&quot;, shape=(?, 43), dtype=float32) 不是这个图的一个元素 - python - ValueError: Tensor Tensor("dense_2/Softmax:0", shape=(?, 43), dtype=float32) is not an element of this graph ValueError: Tensor Tensor(&quot;mrcnn_detection/Reshape_1:0&quot;, shape=(1, 100, 6), dtype=float32) 不是这个图的一个元素 - ValueError: Tensor Tensor("mrcnn_detection/Reshape_1:0", shape=(1, 100, 6), dtype=float32) is not an element of this graph
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM