keras中的预处理输入大大增加了列车的尺寸
在使用resnet50模型进行培训之前,我使用以下方法对输入进行了预处理:keras中的预处理输入大大增加了列车的尺寸,keras,image-preprocessing,Keras,Image Preprocessing,在使用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\u输入,数组的大小是1.5G,
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\u输入
,数组的大小是1.5G,而使用preprocess\u输入,数组的大小是7G。
这是正常的行为吗?还是我遗漏了什么?
为什么Zero center by mean pixel
会大幅增加输入大小
这就是在keras中如何定义平均像素零中心
x=x[…,:-1]
x[…,0]=103.939
x[…,1]=116.779
x[…,2]-=123.68
读取keras实现的预处理输入
通过减去数据集的图像平均值(似乎是从imagenet获得的常数),对图像进行归一化。这是密码
def _preprocess_numpy_input(x, data_format, mode):
if mode == 'tf':
x /= 127.5
x -= 1.
return x
if data_format == 'channels_first':
if x.ndim == 3:
# 'RGB'->'BGR'
x = x[::-1, ...]
# Zero-center by mean pixel
x[0, :, :] -= 103.939
x[1, :, :] -= 116.779
x[2, :, :] -= 123.68
else:
x = x[:, ::-1, ...]
x[:, 0, :, :] -= 103.939
x[:, 1, :, :] -= 116.779
x[:, 2, :, :] -= 123.68
else:
# 'RGB'->'BGR'
x = x[..., ::-1]
# Zero-center by mean pixel
x[..., 0] -= 103.939
x[..., 1] -= 116.779
x[..., 2] -= 123.68
return x
我不明白为什么使用这段代码会增加数据集的大小。阅读keras实现的预处理输入
通过减去数据集的图像平均值(似乎是从imagenet获得的常数),对图像进行归一化。这是密码
def _preprocess_numpy_input(x, data_format, mode):
if mode == 'tf':
x /= 127.5
x -= 1.
return x
if data_format == 'channels_first':
if x.ndim == 3:
# 'RGB'->'BGR'
x = x[::-1, ...]
# Zero-center by mean pixel
x[0, :, :] -= 103.939
x[1, :, :] -= 116.779
x[2, :, :] -= 123.68
else:
x = x[:, ::-1, ...]
x[:, 0, :, :] -= 103.939
x[:, 1, :, :] -= 116.779
x[:, 2, :, :] -= 123.68
else:
# 'RGB'->'BGR'
x = x[..., ::-1]
# Zero-center by mean pixel
x[..., 0] -= 103.939
x[..., 1] -= 116.779
x[..., 2] -= 123.68
return x
我不明白为什么使用这段代码会增加数据集的大小。这是因为像素值的类型是“uint8”,而现在它们的类型是“float”。
现在有了一个图像,它是一个“浮点”数组,比“uint8”数组大。这是因为像素值是“uint8”类型的,而现在它们是“浮点”类型的。
现在有了一个图像,它是一个“float”数组,比“uint8”数组大。根据TensorFlow
理由是:
浮点numpy.array或tf.Tensor,3D或4D,具有3个颜色通道,值在[0255]范围内。
然后函数返回
返回:
预处理的numpy.array或float32类型的tf.Tensor
我感觉整数使用了不同的内存量。根据TensorFlow
理由是:
浮点numpy.array或tf.Tensor,3D或4D,具有3个颜色通道,值在[0255]范围内。
然后函数返回
返回:
预处理的numpy.array或float32类型的tf.Tensor
我感觉整数使用了不同的内存。如何定义preprocess\u输入?你所说的“平均像素零中心”是什么意思?如果你提到“预处理输入”的keras实现,你可以看到这些代码行x[…,0]=103.939x[…,1]=116.779x[…,2]=123.68
。我最终决定使用一个生成器。所以我不需要再担心数据的大小。只预处理了一大块数据,preprocess\u input
是如何定义的?你所说的“平均像素零中心”是什么意思?如果你提到“预处理输入”的keras实现,你可以看到这些代码行x[…,0]=103.939x[…,1]=116.779x[…,2]=123.68
。我最终决定使用一个生成器。所以我不需要再担心数据的大小。只对一大块数据进行了预处理