首页 PaddleHub 帖子详情
Paddle2.0.0版本后默认使用动态图,请问静态图在2.0后版本的上要如何运行?
收藏
快速回复
PaddleHub 问答预训练模型 578 1
Paddle2.0.0版本后默认使用动态图,请问静态图在2.0后版本的上要如何运行?
收藏
快速回复
PaddleHub 问答预训练模型 578 1

版本信息:
PaddlePaddle2.1.2
PaddleHub2.0.4
Python3.7.4
环境:
Windows使用的AIStudio

相关代码:

import paddle

from paddlehub.finetune.trainer import Trainer

# optimizer = paddle.optimizer.Adam(learning_rate=0.001, parameters=model.parameters())

trainer = Trainer(model, None, checkpoint_dir='img_classification_ckpt')

利用AIStudio进行 finetune 训练时, trainer = Trainer(model, None, checkpoint_dir='img_classification_ckpt') 报错AttributeError: 'ResNet50vdAnimals' object has no attribute 'name';

详细报错如下:
---------------------------------------------------------------------------AttributeError Traceback (most recent call last) in
7
8
----> 9 trainer = Trainer(model, None, checkpoint_dir='img_classification_ckpt')
10
11 trainer.train(flowers, epochs=100, batch_size=32, eval_dataset=flowers_validate, save_interval=1)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/trainer.py in init(self, model, optimizer, use_gpu, use_vdl, checkpoint_dir, compare_metrics, **kwargs)
67
68 if not isinstance(self.model, paddle.nn.Layer):
---> 69 raise TypeError('The model {} is not a paddle.nn.Layer object.'.format(self.model.name))
70
71 if self.local_rank == 0 and not os.path.exists(self.checkpoint_dir):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/module/module.py in getattribute(self, attr)
87 # execution of the static graph model to fail, so compatibility protection is required.
88 def getattribute(self, attr):
---> 89 _attr = object.getattribute(self, attr)
90
91 # If the acquired attribute is a built-in property of the object, skip it.
AttributeError: 'ResNet50vdAnimals' object has no attribute 'name'

查看PaddleHubAPI后发现2.0.0版本后Paddle默认使用动态图,会导致静态图模型执行失败; ResNet50vdAnimals模型传入后提示不属于paddle.nn.Layer, 请问动态图在2.0.0之后的版本上要如何运行?

# After the 2.0.0rc version, paddle uses the dynamic graph mode by default, which will cause the
# execution of the static graph model to fail, so compatibility protection is required.
def __getattribute__(self, attr):
_attr = object.__getattribute__(self, attr)

# If the acquired attribute is a built-in property of the object, skip it.
if re.match('__.*__', attr):
return _attr
# If the module is a dynamic graph model, skip it.
elif isinstance(self, paddle.nn.Layer):
return _attr
# If the acquired attribute is not a class method, skip it.
elif not inspect.ismethod(_attr):
return _attr

return paddle_utils.run_in_static_mode(_attr)

0
收藏
回复
全部评论(1)
时间顺序
小姐姐都是我的
#2 回复于2021-08

你好,ResNet50vdAnimals是不支持 finetune的

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户