[英]tf.data.Dataset.from_tensor_slices, tensors and eager mode
[英]How can I get tf.data.Dataset.from_tensor_slices to accept my dtype?
# 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
您可以通過對兩個張量的元組進行切片,將兩個張量組合成一個 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))
請注意,張量在它們的第一維中應該具有相同的大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.