Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Keras 如何在低分辨率图像(如tiny imagenet数据集)上使用预训练模型_Keras_Vgg Net_Pre Trained Model_Imagenet - Fatal编程技术网

Keras 如何在低分辨率图像(如tiny imagenet数据集)上使用预训练模型

Keras 如何在低分辨率图像(如tiny imagenet数据集)上使用预训练模型,keras,vgg-net,pre-trained-model,imagenet,Keras,Vgg Net,Pre Trained Model,Imagenet,我下载了微型imagenet数据集,它是imagenet数据集的一个子集,其图像大小为64*64像素。我想使用原始imagenet上的预训练模型,如alexnet和VGG,并将tiny imagenet的图像作为网络输入。是真是假? 正如您所知,原始imagenet中的图像分辨率高于微型imagenet。这会导致推理任务出现问题吗? 感谢您的关注。通常,CNN层可用于任何大小的图像。CNN层中权重的数量并不取决于图像大小,而是取决于内核的数量和形状。例如: Conv2D(16, (3, 3),

我下载了微型imagenet数据集,它是imagenet数据集的一个子集,其图像大小为64*64像素。我想使用原始imagenet上的预训练模型,如alexnet和VGG,并将tiny imagenet的图像作为网络输入。是真是假? 正如您所知,原始imagenet中的图像分辨率高于微型imagenet。这会导致推理任务出现问题吗?
感谢您的关注。

通常,CNN层可用于任何大小的图像。CNN层中权重的数量并不取决于图像大小,而是取决于内核的数量和形状。例如:

Conv2D(16, (3, 3), padding="same",input_shape=(None, None, 3))
始终具有16(内核)*3*3*3(通道)+16(偏差)=448个权重

唯一的问题是,网络的头部通常是一组具有固定数量输入的密集层。因此,如果您只是在
Conv2D
Dense
层之间展平网络,则图像的大小必须固定。但是,如果您将例如
tf.keras.layers.globalaveragepoolig2d
层放入,则图像的大小可能是可变的,因为该层生成的输出仅取决于内核的数量,而不取决于图像的大小

如果您使用带有标题的版本(
include_top
parameter):

您可以使用
base\u model.summary()
检查他们希望图像大小(224,3)。 但是如果您添加
include\u top=False
如下:

base_model = tf.keras.applications.VGG16(weights = 'imagenet', include_top = False)
图像的预期输入形状为
(无,无,3)
。这种用于大小
(W,H,3)
的图像的网络产生大小
(W/S,H/S,K)
的输出,其中K是最后一层中的内核数,S是特定网络的收缩因子。例如,对于VGG16网络S=32和K=512,因此对于大小为(224224,3)的图像,输出大小为(7,7512),对于大小为(512512,3)的图像,输出大小为(16,16512)。这种输出有时称为“补丁”

因此,如果您想构建一个使用一些预训练网络并对任意大小的图像进行分类的网络,您可以这样构建:

base_model = tf.keras.applications.ResNet50(weights = 'imagenet', include_top = False)
x = base_model.output
x = tf.keras.layers.GlobalAveragePooling2D()(x)
x = tf.keras.layers.Dense(512, activation = 'relu')(x)
...
last_layer = tf.keras.layers.Dense(num_classes, activation = 'softmax')(x)
model = tf.keras.models.Model(inputs = base_model.input, outputs = last_layer)
这样的模型可以输入任何大小的图像,并为
num_类
类生成概率向量。当然,在培训期间,您必须在同一批中使用相同大小的图像,但之后您可以使用任何图像

base_model = tf.keras.applications.VGG16(weights = 'imagenet', include_top = False)
base_model = tf.keras.applications.ResNet50(weights = 'imagenet', include_top = False)
x = base_model.output
x = tf.keras.layers.GlobalAveragePooling2D()(x)
x = tf.keras.layers.Dense(512, activation = 'relu')(x)
...
last_layer = tf.keras.layers.Dense(num_classes, activation = 'softmax')(x)
model = tf.keras.models.Model(inputs = base_model.input, outputs = last_layer)