【发布时间】:2022-01-25 05:54:55
【问题描述】:
我正在尝试使用 CNN 创建图像分类模型。为此,我正在使用tf.keras.preprocessing.image_dataset_from_directory 函数读取数据。
这是代码:
train_ds = tf.keras.preprocessing.image_dataset_from_directory(data_dir_train,seed=123,validation_split = 0.2,subset = 'training',image_size=(img_height, img_width),batch_size=batch_size)
然后我尝试在 np.array 对象中转换数据集。我的代码是
x_train = np.array(train_ds)
但是当我打印 x_train 时,我得到了
array(<BatchDataset shapes: ((None, 180, 180, 3), (None,)), types: (tf.float32, tf.int32)>, dtype=object)
对象train_ds 的形状为(2000,180,180,3)。我不确定我的代码有什么问题。
【问题讨论】:
-
你期望得到什么?
-
@richardec : 为什么会出现 ((None, 180, 180, 3), (None,))。我觉得应该是(2000,180,180,3)
标签: python numpy tensorflow keras conv-neural-network