在PyTorch中从预先训练的模型中提取ResNet特征之前对图像进行预处理

时间:2020-03-16 17:47:41

标签: python pytorch feature-extraction resnet

我需要提取ResNet功能(最终转换层的输出,就在全局平均池化层之前)。我发现代码herehere如下

res50_model = models.resnet50(pretrained=True)
res50_conv = nn.Sequential(*list(res50_model.children())[:-2])
outputs = res50_conv(inputs)

在Keras中,我可以执行以下操作:

from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input

resnet_model = ResNet50(include_top=False)
preprocessed_images = preprocess_input(images)
features = self.model.predict(preprocessed_images)

Keras中的preprocess_inputimages中减去ImageNet均值,并执行其他一些预处理步骤。 pytorch也需要吗?如果是这样,该怎么做?有内置功能吗?

0 个答案:

没有答案