gpt4 book ai didi

python - VGG16 模型的 OpenCV Python 图像预处理

转载 作者:行者123 更新时间:2023-12-04 13:35:28 24 4
gpt4 key购买 nike

我想正确地预处理图像以将它们输入到 VGG16 模型中

在他们的 original paper作者写道:

During training, the input to our ConvNets is a fixed-size 224 × 224 RGB image. The only preprocessing we do is subtracting the mean RGB value, computed on the training set, from each pixel.

调整大小的部分很容易完成:

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. 从所有训练集图像中减去这个均值?

最佳答案

尝试:

from keras.applications.vgg16 import preprocess_input
...
resized_image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
processedimage = preprocess_input(resized_image)

来自: https://www.pyimagesearch.com/2016/08/10/imagenet-classification-with-python-and-keras/

关于python - VGG16 模型的 OpenCV Python 图像预处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62370995/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com