Awesome pre-trained models toolkit based on PaddlePaddle. (400+ models including Image, Text, Audio, Video and Cross-Modal with Easy Inference & Serving)【安全加固,暂停交互,请耐心等待】
利用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'
# 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)
版本信息: PaddlePaddle2.1.2 PaddleHub2.0.4 Python3.7.4 环境: Windows使用的AIStudio
相关代码:
利用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之后的版本上要如何运行?