输入图像大小

2024-09-27 17:57:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一组大小为200x600(WxH)的图像,但当我使用pyplot显示它时,它们的大小看起来像是600x200

train_ds = tf.keras.preprocessing.image_dataset_from_directory(
    data_dir,
    validation_split=0.2,
    subset="training",
    seed=123,
    image_size=(200, 600),
    batch_size=batch_size)

我不知道为什么会这样。当我将其更改为image_size=(600200)时,它看起来不错,但tensorflowjs对形状表示不满

let tensorImg = tf.browser.fromPixels(canvas).resizeNearestNeighbor([200, 600]).toFloat().expandDims();

有什么提示吗


Tags: from图像imagedatasizetfbatchds
1条回答
网友
1楼 · 发布于 2024-09-27 17:57:16

我用自己的数据集测试了它的工作情况。 下面的示例代码

batch_size = 32
img_height = 200
img_width = 600

train_ds = tf.keras.utils.image_dataset_from_directory(
  data_dir,
  validation_split=0.2,
  subset="training",
  seed=123,
  image_size=(img_height, img_width),
  batch_size=batch_size)

val_ds = tf.keras.utils.image_dataset_from_directory(
  data_dir,
  validation_split=0.2,
  subset="validation",
  seed=123,
  image_size=(img_height, img_width),
  batch_size=batch_size)

for image_batch, labels_batch in train_ds:
  print(image_batch.shape)
  print(labels_batch.shape)
  break

输出:

(32, 200, 600, 3)
(32,)

相关问题 更多 >

    热门问题