首页 > 解决方案 > keras 中的 preprocess_input 大大增加了火车的大小

问题描述

在使用 resnet50 模型进行训练之前,我使用以下方法预处理了我的输入:

img = image.load_img(os.path.join(TRAIN, img), target_size=[224, 224])
img = image.img_to_array(img)
img = np.expand_dims(img, axis=0)
img = preprocess_input(img)

并保存一个 numpy 图像数组。我发现没有preprocess_input,数组的大小是1.5G,有preprocess_input,大小是7G。这是正常行为吗?还是我错过了什么?为什么Zero-center by mean pixel大幅增加输入大小?

这就是zero center by mean pixel在 keras 中定义的方式

x = x[..., ::-1] x[..., 0] -= 103.939 x[..., 1] -= 116.779 x[..., 2] -= 123.68

标签: kerasimage-preprocessing

解决方案


这是因为像素值的类型为“uint8”,而现在它们的类型为“float”。所以现在你有一个图像,它是一个'float'数组,它大于'uint8'数组。


推荐阅读