【问题标题】:Preprocessing for using VGG model with VGGFace weights使用带有 VGGFace 权重的 VGG 模型的预处理
【发布时间】:2019-01-21 23:22:58
【问题描述】:

使用预训练的 VGGFace 权重训练微调的 VGG 模型需要执行哪些预处理步骤?

我正在尝试将大小为 224x224x3 的图像数组放入我的微调 VGG 模型(冻结网络的最后 4 层),并在其上添加一些 Dense 层。训练需要很多时间,但我得到的准确率非常低,不到 1% 的准确率,而且模型根本不会学习。

我用过这个:

vgg16.preprocess_input(img_array)

我希望我的模型至少能够学习,如果不能给出很好的准确性的话。我可能做错了什么?

【问题讨论】:

  • img_array的范围是多少?预处理函数将使用从 0 到 255 的原始图像。

标签: keras vgg-net


【解决方案1】:

您可以在 github 上查看确切的预处理逻辑。对于VGG16,使用了imagenet的通用预处理功能。你可以找到函数here。它非常冗长,因为它适用于 numpy 数组和张量,但文档字符串中描述了它的作用:

x: Input Numpy or symbolic tensor, 3D or 4D.
    The preprocessed data is written over the input data
    if the data types are compatible. To avoid this
    behaviour, `numpy.copy(x)` can be used. data_format: Data format of the image tensor/array. mode: One of "caffe", "tf" or "torch".
    - caffe: will convert the images from RGB to BGR,
        then will zero-center each color channel with
        respect to the ImageNet dataset,
        without scaling.
    - tf: will scale pixels between -1 and 1,
        sample-wise.
    - torch: will scale pixels between 0 and 1 and then
        will normalize each channel with respect to the
        ImageNet dataset.

【讨论】:

    猜你喜欢
    • 2019-06-16
    • 1970-01-01
    • 2018-08-03
    • 2018-12-07
    • 2018-03-19
    • 1970-01-01
    • 2021-11-30
    • 2020-08-13
    • 1970-01-01
    相关资源
    最近更新 更多