keras和tf.keras中的ResNet模型对于同一张图像给出不同的输出 [英] ResNet model in keras and tf.keras give different output for the same image

查看:138
本文介绍了keras和tf.keras中的ResNet模型对于同一张图像给出不同的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于给定的图像,我正在提取ResNet功能,即在所有conv层和全局最大池化之后,每个图像提供2048个长度的向量.

For a given image, I'm extracting ResNet features i.e. after all conv layers and global max pooling, which gives a 2048 length vector per image.

之前,我使用的是 keras == 2.3.1 和后端 tensorflow == 1.13.1 .现在,由于keras已与tensorflow合并,因此我转到了 tensorflow == 2.0.0 .我用 tf.keras 而不是 keras 替换了代码.

Earlier, I was using keras==2.3.1 with backend tensorflow==1.13.1. Now, I've shifted to tensorflow==2.0.0 since keras has been merged with tensorflow. I replaced my code with tf.keras instead of keras.

但是现在提取的特征与之前提取的特征不同.ResNet是一个独立于张量流/keras甚至pytorch的模型.它的功能是预定义的.为什么会出现这种差异?是否可以调整任何参数以获得相同的功能?

But now the features extracted are not the same as the features extracted earlier. ResNet is a model which is independent of tensorflow/keras or even pytorch for that matter. It's functionality is predefined. Why is this difference occuring? Are there any parameters that can be tweaked to get the same functionality?

编辑1 :添加代码

from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input
resnet_model = ResNet50(include_top=False)

推荐答案

模型本身不断更新,并且使用权重更好的结果.此处是发布文件夹,您可以在其中查看不同重量文件的发布.链接的文件夹用于keras,tf.keras也很可能使用了该文件夹.您面临的问题可能是由于库的版本而不是模型的调用方法引起的.

The models themselves keep updating and the weights with better results are used. Here is the releases folder where you can see releases of different weight files. The folder linked is for keras, which is most probably also used by tf.keras. The problem you are facing is probably because of the version of library rather than method of calling the model.

例如,在此处您可以找到keras_applications代码,并检查指向发布v0.2的权重路径(链接为keras,但对于tensorflow.keras同样).

For example, here you can find the keras_applications code and check the weight path which points to release v0.2(linked is keras but similarly for tensorflow.keras).

较旧的库版本具有较旧的链接,更新库也会更新路径.

The older library versions have older links, updating the libraries also updates the paths.

这篇关于keras和tf.keras中的ResNet模型对于同一张图像给出不同的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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