更改VGG16应用的输入张量形状 [英] Change input tensor shape for VGG16 application

查看:748
本文介绍了更改VGG16应用的输入张量形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将形状为(160,320,3)的图像输入到

I want to feed images with the shape (160,320,3) to

 VGG16(input_tensor=input_tensor, include_top=False)   

我如何包含一个将图像重塑为VGG16模型期望的形状(即(224,224,3))的层?

How can I include a layer that reshapes the images to the shape expected by the VGG16 model, which is (224,224,3) ?

推荐答案

VGG16模型本身只是一组固定的层序列和固定的卷积核大小的权重.这并不意味着这些卷积内核不能应用于其他尺寸的图像.

VGG16 model in itself is just a set of weights of the fixed sequence of layers and fixed convolution kernel sizes etc. That doesn't mean that those convolution kernels cannot be applied to images of other sizes.

例如,您的情况:

from keras.models import Model
from keras.layers import Dense,Flatten
from keras.applications import vgg16
from keras import backend as K

model = vgg16.VGG16(weights='imagenet', include_top=False, input_shape=(160,320,3))
model.summary(line_length=150)

flatten = Flatten()
new_layer2 = Dense(10, activation='softmax', name='my_dense_2')

inp2 = model.input
out2 = new_layer2(flatten(model.output))

model2 = Model(inp2, out2)
model2.summary(line_length=150)

根据此处最小图像大小可以是48x48x3,大于此值可以.

According to here the minimum image size can be 48x48x3 anything above than that is fine.

现在,它的真实权重是在224,224,3形状的图像上学习的,但是滤镜权重对于使用新图像集的新任务来说是非常好的起点.您确实需要重新训练网络,但是网络将很快收敛.这是转学的基础.

Now its true the original weights were learnt on 224,224,3 shaped images but the filters weights act as very good starting point for new tasks with new set of images. You do need to re-train the network but the network would converge very quickly. This is the basis of transfer learning.

这篇关于更改VGG16应用的输入张量形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆