【发布时间】:2021-02-18 19:00:52
【问题描述】:
您好,我正在预处理一些图像数据以在简单的 FF 网络中运行:
我有两个选项在我看来是相同的,但一个比另一个执行得好很多:
选项 1
我将图像保存在具有相应子目录的目录中并运行:
xy_training = tf.keras.preprocessing.image_dataset_from_directory("/content/data/train", image_size=(48,48), color_mode='grayscale',label_mode="int")
xy_validation = tf.keras.preprocessing.image_dataset_from_directory("/content/data/valid", image_size=(48,48), color_mode='grayscale',label_mode="int")
xy_testing = tf.keras.preprocessing.image_dataset_from_directory("/content/data/test", image_size=(48,48), color_mode='grayscale',label_mode="int")
选项 2 我有灰度图像的原始数组并执行此操作
def preprocess(data):
X = []
pixels_list = data["pixels"].values
for pixels in pixels_list:
single_image = np.reshape(pixels.split(" "), (WIDTH,HEIGHT)).astype("float")
X.append(single_image)
# Convert list to 4D array:
X = np.expand_dims(np.array(X), -1)
# Normalize pixel values to be between 0 and 1
X = X / 255.0
return X
train_images= preprocess(train_data)
valid_images= preprocess(valid_data)
test_images= preprocess(test_data)
选项 2 的效果比 选项 1 好得多。 tf.keras.preprocessing.image_dataset_from_directory(里面有没有参数我没设置?
谢谢!
【问题讨论】:
标签: python image tensorflow keras image-preprocessing