Python 如何从张量切片获取tf.data.Dataset.from_tensor_切片以接受我的数据类型?

Python 如何从张量切片获取tf.data.Dataset.from_tensor_切片以接受我的数据类型?,python,tensorflow,dtype,Python,Tensorflow,Dtype,下面的代码就是我在Tensorflow 2中使用的代码,我不断地更改我转换的类型,但是无论我使用哪种类型,它都会不断地给我错误。有什么想法吗?下面我列出了我遇到的一些错误: # 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, shuffl

下面的代码就是我在Tensorflow 2中使用的代码,我不断地更改我转换的类型,但是无论我使用哪种类型,它都会不断地给我错误。有什么想法吗?下面我列出了我遇到的一些错误:

# 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.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

请注意,张量在其第一维中的大小应该相同。

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

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
请注意,张量在其第一维中的大小应该相同