为什么插入频道数不起作用?

问题描述 投票:0回答:1
num_x_train = (x_train.shape[0])
num_x_val = (x_val.shape[0])
num_x_test = (x_test.shape[0])

print("trian data : {}\tlabel : {}".format(x_train_full.shape, y_train_full.shape,img.channel))
print("train data : {}\tlabel : {}".format(x_train.shape, y_train.shape,))
print("val data : {}\tlabel : {}".format(x_val.shape, y_val.shape,))
print("test data : {}\tlabel : {}".format(x_test.shape, y_test.shape,))

num_sample = 5

random_idxs = np.random.randint(6000, size = num_sample)

plt.figure(figsize=(14,8))
for i, idx in enumerate(random_idxs):
  img = x_train_full[idx,:]
  label = y_train_full[idx]

  plt.subplot(1, len(random_idxs), i+1)
  plt.imshow(img)
  plt.title("Index: {}, Label : {}".format(idx, label))

plt.show()`

在 print() 部分,我想显示编码中使用的通道数。目前使用黑白图像。 我试图编辑代码,但没有成功。 我该如何解决这个问题?

结果的期望看起来像火车数据:(60000、28、28、1)

python channels
1个回答
0
投票

您好,欢迎君!

您的 img.channel 未打印,因为在您的以下格式字符串中没有占位符:

print("trian data : {}\tlabel : {}".format(x_train_full.shape, y_train_full.shape,img.channel))

要让它工作,您需要添加必要的第三个占位符,如下所示:

print("trian data : {}\tlabel : {}, channels: {}".format(x_train_full.shape, y_train_full.shape, img.channel))

如果您使用 Python 3.6 或更高版本,您还可以使用 f 字符串格式

print(f"trian data : {x_train_full.shape}\tlabel : {y_train_full.shape}, channels: {img.channel}")

希望对您有所帮助!

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.