保存模型时报错
分寸之末末末 发布于2021-05 浏览:839 回复:0
0
收藏
快速回复
最后编辑于2021-05

参照课程【百度架构师手把手带你零基础实践深度学习>10 【手写数字识别】之动转静部署】进行模型保存

AIStudio上运行提示下述警告后,模型得已保存

/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/jit.py:412: UserWarning: The InputSpec(shape=(-1, 784), dtype=VarType.FP32, name=None)'s name is None. When using jit.save, please set InputSepc's name in to_static(input_spec=[]) and jit.save(input_spec=[]) and make sure they are consistent.
warnings.warn(name_none_error % spec)

但是在本地运行自己的模型时,保存的时候却直接报错,错误如下

C:\Users\user.DESKTOP-EP53762\AppData\Roaming\Python\Python37\site-packages\paddle\fluid\layers\utils.py:77: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
return (isinstance(seq, collections.Sequence) and
epoch: 1, batch: 1, loss is: [7.680747], acc is [0.02]
2021-05-07 21:29:44,212 Dynamic-to-Static WARNING: Current function: forward(inputs,label), input_spec: None has more than one cached programs: 2, the last traced progam will be return by default.
Traceback (most recent call last):
File "F:/Python/PolSAR_CNN/train.py", line 227, in
input_spec=[InputSpec(shape=[None, 9, 15, 15], dtype='float32')])
File "C:\Users\user.DESKTOP-EP53762\AppData\Roaming\Python\Python37\site-packages\decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "C:\Users\user.DESKTOP-EP53762\AppData\Roaming\Python\Python37\site-packages\paddle\fluid\wrapped_decorator.py", line 25, in __impl__
return wrapped_func(*args, **kwargs)
File "C:\Users\user.DESKTOP-EP53762\AppData\Roaming\Python\Python37\site-packages\paddle\fluid\dygraph\base.py", line 39, in __impl__
return func(*args, **kwargs)
File "C:\Users\user.DESKTOP-EP53762\AppData\Roaming\Python\Python37\site-packages\paddle\fluid\dygraph\jit.py", line 704, in save
inner_input_spec)
File "C:\Users\user.DESKTOP-EP53762\AppData\Roaming\Python\Python37\site-packages\paddle\fluid\dygraph\jit.py", line 423, in _get_input_var_names
raise ValueError(name_none_error % spec)
ValueError: The InputSpec(shape=(-1, 9, 15, 15), dtype=VarType.FP32, name=None)'s name is None. When using jit.save, please set InputSepc's name in to_static(input_spec=[]) and jit.save(input_spec=[]) and make sure they are consistent.

保存模型的代码如下

paddle.jit.save(layer=model, path="./model", input_spec=[InputSpec(shape=[None, 9, 15, 15], dtype='float32')])

收藏
点赞
0
个赞
TOP
切换版块