TypeError: object() takes no parameters (自定义的类与导入的模块重名导致的)

TypeError:object() takes no parameters

Traceback (most recent call last):
  File "vgg16_train.py", line 132, in <module>
    finalAct="sigmoid")
  File "/home/data/zpp/work2/pyimagessearch/pyimagesearch/vggnet16.py", line 33, in build
    base_model = ResNet50(weights='imagenet',include_top=False,pooling='avg')
TypeError: object() takes no parameters

问题描述:我首先在 module vggnet16.py 中定义了一个类 class RseNet50, 然后我在主程序中引用这个类,代码如下:

from vggnet16 import ResNet50

...
model = Resnet50.build(
        width=IMAGE_DIMS[1], height=IMAGE_DIMS[0],
        depth=IMAGE_DIMS[2], classes=len(mlb.classes_),
        finalAct="sigmoid")

发生错误:TypeError: object() takes no parameters

错误原因为:在自定义的模块 vggnet16.py 中, 类 ResNet50 与 导入的模块 ResNet50 重名。自定义的类应避免与导入的模块重名。

vggnet16.py

# import the necessary packages
from keras.models import Model
from keras.layers import Dense
from keras.applications.resnet50 import ResNet50


class ResNet50:
    @staticmethod
    def build(width,height,depth,classes,finalAct="softmax"):
        # initialize the model along with the input shape to be
        # "channels last" and the channels dimension itself
        width = 224
        width = 224
        depth = 3
        base_model = ResNet50(weights='imagenet',include_top=False,pooling='avg')
        # first (and only) set of FC => RELU layers
        fc1 = Dense(1024, activation='relu')(base_model.output)
        # softmax classifier
        predications = Dense(classes, activation=finalAct)(fc1)
        model = Model(inputs=base_model.input, outputs=predications)
        # return the constructed network architecture
        return model

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值