xiaomaxiao / PSENET

keras implementation of PSENET
79 stars 23 forks source link

将网络模型和权重一起保存失败 #18

Closed HansRen1024 closed 4 years ago

HansRen1024 commented 4 years ago

您好,首先感谢您开源PSENet的训练和测试代码和模型。

我想把模型和权重一起保存,也就是用keras中Model.save()这个接口,但是遇到了问题。能麻烦帮忙看一下嘛。谢谢!

系统是Ubuntu16.04 IDE是pycharm 专业版 python版本是3.6.8 keras版本是2.2.4 tensorflow版本是1.13.1

错误输出为: Traceback (most recent call last): File "/home/hans/WorkSpace/Rand2AI/CoreDL/Model/Detector/PSENet/PSENet_test.py", line 120, in <module> net.deviceModel.save('/home/hans/WorkSpace/MODEL/PSENet_Model.h5') File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/site-packages/keras/engine/network.py", line 1090, in save save_model(self, filepath, overwrite, include_optimizer) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/site-packages/keras/engine/saving.py", line 382, in save_model _serialize_model(model, f, include_optimizer) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/site-packages/keras/engine/saving.py", line 83, in _serialize_model model_config['config'] = model.get_config() File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/site-packages/keras/engine/network.py", line 931, in get_config return copy.deepcopy(config) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 150, in deepcopy y = copier(x, memo) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 240, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 150, in deepcopy y = copier(x, memo) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 215, in _deepcopy_list append(deepcopy(a, memo)) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 150, in deepcopy y = copier(x, memo) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 240, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 150, in deepcopy y = copier(x, memo) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 240, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 150, in deepcopy y = copier(x, memo) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 220, in _deepcopy_tuple y = [deepcopy(a, memo) for a in x] File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 220, in <listcomp> y = [deepcopy(a, memo) for a in x] File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 150, in deepcopy y = copier(x, memo) File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 220, in _deepcopy_tuple y = [deepcopy(a, memo) for a in x] File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 220, in <listcomp> y = [deepcopy(a, memo) for a in x] File "/home/hans/WorkSpace/venv/Rand2AI/lib/python3.6/copy.py", line 169, in deepcopy rv = reductor(4) TypeError: can't pickle module objects

HansRen1024 commented 4 years ago

解决了这个问题。在def resnet_v1_50_fn(inputs, include_top=False, weight='imagenet')中,将去均值的操作放到预处理上就好了,不能在网络中这样做。

HansRen1024 commented 4 years ago

读取模型的时候提示找不到自定义层,然后将resize_image类作为自定义层添加进去后,又提示错误缺少自定义层的输入参数。呃,暂时放弃挣扎了,先老老实实测试再说吧。