‘无法计算 Pack 作为输入 #1(从零开始)应该是一个浮点张量,但它是一个 int32 张量 [Op:Pack] 名称:packed’。 tf.squeeze 出错
machine-learning 438
原文标题 :‘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
我正在尝试在带有预测的图上显示数据集的图像。但是我有这个错误:cannot compute Pack as input #1(zero-based) was expected to be a float tensor but is a int32 tensor [Op:Pack] name: packed
这是我绘制的代码:
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 函数的第二行有错误。我想删除图像形状的第一维(形状是 (18, 360, 360, 3),我想要 (360, 360, 3))。
回复
我来回复-
AloneTogether 评论
该回答已被采纳!
您忘记在循环中引用您的标签。尝试这样的事情:
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")
2年前