Python中使用OpenCV进行VGG16模型的图像预处理

3
我希望您能正确预处理图像,以将其输入VGG16模型。
在他们的原始论文中,作者写道:
在训练期间,我们ConvNets的输入是一个固定大小为224×224的RGB图像。我们唯一做的预处理是从每个像素中减去在训练集上计算出的平均RGB值。
调整大小部分很容易完成:
import cv2
import numpy as np


# Reading the image in RGB mode
image = cv2.imread(PATH_TO_IMAGE,1)

# Resize Image to original VGG16 input size
# from the paper: "During training, the input to our ConvNets 
# is a fixed-size 224 × 224 RGB image"

width = 224
height = 224
dim = (width, height)

# resize image
resized_image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)

...但我不确定减去平均RGB值的作用:

meanRBB_substract_image = resized_image - np.mean(resized_image)

这是正确的方法吗?

在进行RGB减法之前:

enter image description here

减去平均RGB后:

enter image description here

关于VGG16模型的更多信息:https://neurohive.io/en/popular-networks/vgg16/#:~:text=The%20architecture%20depicted%20below%20is%20VGG16.&text=The%20input%20to%20cov1%20layer,stack%20of%20convolutional%20(conv.)

编辑:我刚才意识到他们写道“在训练集上计算”->这是否意味着我需要 1. 找到训练集中所有图片的平均RGB值,然后2.从所有训练集图像中减去这个平均值?


你看到我的回答了吗?@henry - Stackaccount1
1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接