检查一个变量是否是ResNet50的实例。

huangapple go评论70阅读模式
英文:

Check whether a variable is instance of ResNet50

问题

以下是翻译好的代码部分:

我正在检查是否

    model = ResNet50(weights='imagenet', include_top=False, pooling="avg")


    keras.applications.ResNet50

的实例

我已经尝试过

    isinstance(model, ResNet50)

但不幸的是这引发了以下异常

> TypeError: isinstance()的第二个参数必须是一个类型类型元组或联合类型

此外我也尝试过

    isinstance(model, keras.applications.ResNet50())

但同样这引发了相同的异常

- 我漏掉了什么
英文:

I am checking whether

model = ResNet50(weights='imagenet', include_top=False, pooling="avg")

is instance of

keras.applications.ResNet50

What I have done is:

isinstance(model, ResNet50)

but unfortunately this is raising me the following exception:

> TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

Moreover, I have tried:

isinstance(model, keras.applications.ResNet50())

but, again, this is raising me the same exception.

  • What am I missing?

答案1

得分: 1

keras.applications.ResNet50 是一个返回 keras.models.Model 实例的函数。

尝试:

if model.name == "resnet50":
    ...
英文:

keras.applications.ResNet50 is a function that returns an instance of keras.models.Model.

Try:

if model.name == "resnet50":
    ...

huangapple
  • 本文由 发表于 2023年3月7日 18:50:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75661029.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定