[英]cannot compute Add as input #1(zero-based) was expected to be a int32 tensor but is a double tensor [Op:Add]
[英]'cannot compute Pack as input #1(zero-based) was expected to be a float tensor but is a int32 tensor [Op:Pack] name: packed'. Error with tf.squeeze
我正在嘗試在 plot 上顯示數據集的圖像及其預測。 但我有這個錯誤: cannot compute Pack as input #1(zero-based) was expected to be a float tensor but is a int32 tensor [Op:Pack] name: packed
這是我 plot 的代碼:
for images in val_ds.take(1):
tf.squeeze(images, [0])
for i in range(18):
ax = plt.subplot(6, 6, i + 1)
plt.imshow(images[i].numpy().astype("uint8"))
#plt.title(predictions[i])
plt.axis("off")
我在第二行有錯誤,在 tf.squeeze function 上。 我想刪除圖像形狀的第一維(形狀是(18、360、360、3),我想要(360、360、3))。
您忘記在循環中引用您的標簽。 嘗試這樣的事情:
import tensorflow as tf
import pathlib
import matplotlib.pyplot as plt
dataset_url = "https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz"
data_dir = tf.keras.utils.get_file('flower_photos', origin=dataset_url, untar=True)
data_dir = pathlib.Path(data_dir)
batch_size = 18
val_ds = tf.keras.utils.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="validation",
seed=123,
image_size=(360, 360),
batch_size=batch_size)
for images, _ in val_ds.take(1):
for i in range(18):
ax = plt.subplot(6, 6, i + 1)
plt.imshow(images[i].numpy().astype("uint8"))
plt.axis("off")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.