python - Keras 输入图像大小
问题描述
我有一组大小为 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=(600, 200)时,它看起来不错,但 tensorflowjs 抱怨形状。
let tensorImg = tf.browser.fromPixels(canvas).resizeNearestNeighbor([200, 600]).toFloat().expandDims();
有什么提示吗?
解决方案
我用我自己的数据集测试了它按预期工作。 下面的示例代码
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,)
推荐阅读
- excel - 来自宏录制的 excel 宏中的错误应用程序定义或对象定义错误
- azure - 在 python 中的 aks 中缩放 pod
- python - 根据目标值绘制熊猫数据帧的分布
- angular - Angular NPM - 找不到 mime@1.6.0 的匹配版本
- python - 如何在 Python 中更改海龟长度
- nuxt.js - 延迟加载导入图像到 vuetify/nuxt.js
- c++ - 程序在输入空格时停止。即使使用 cin.getline
- javascript - 我无法在反应中访问数组的索引
- javascript - 从 gs 文件中的函数返回值到 javascript 文件 (HTML)
- http - 在不同的请求中获取相同的 html 正文