【问题标题】:How can I get tf.data.Dataset.from_tensor_slices to accept my dtype?如何让 tf.data.Dataset.from_tensor_slices 接受我的 dtype?
【发布时间】:2020-04-02 15:31:07
【问题描述】:
# Convert to Tensor
imagepaths = tf.convert_to_tensor(imagepaths, dtype=tf.string)
labels = tf.convert_to_tensor(labels, dtype=tf.int32)
# Build a TF Queue, shuffle data
image, label = tf.data.Dataset.from_tensor_slices([imagepaths, labels])

所以下面的代码是我在 Tensorflow 2 中使用的代码,我不断更改我转换为的类型,但是无论我使用哪个,它都会不断地给我错误。有任何想法吗?下面我列出了我得到的一些错误:

tensorflow.python.framework.errors_impl.InvalidArgumentError: cannot compute Pack as input #1(zero-based) was expected to be a string tensor but is a int32 tensor [Op:Pack] name: component_0


return ops.EagerTensor(value, handle, device, dtype)
TypeError: Cannot convert provided value to EagerTensor

【问题讨论】:

    标签: python tensorflow dtype


    【解决方案1】:

    您可以通过切片两个张量的元组将两个张量组合成一个 Dataset 对象。 像这样:

    # Convert to Tensor
    imagepaths = tf.convert_to_tensor(imagepaths, dtype=tf.string)
    labels = tf.convert_to_tensor(labels, dtype=tf.int32)
    # Build a TF Queue, shuffle data
    dataset = tf.data.Dataset.from_tensor_slices((imagepaths, labels))
    

    请注意,张量在它们的第一维中应该具有相同的大小。

    【讨论】:

      猜你喜欢
      • 2016-01-16
      • 1970-01-01
      • 2023-03-21
      • 2015-12-30
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      • 2019-09-29
      • 1970-01-01
      相关资源
      最近更新 更多