我对keras实施了RCAN [https://arxiv.org/pdf/1807.02758.pdf],并训练了模型。
此后,我尝试照常保存模型,但是突然它输出错误并且不保存模型。
我的整个代码在这里:
https://github.com/moonchildz/RCAN-keras/blob/master/rca_keras.py
这是错误消息:
File "C:/Users/Administrator/PycharmProjects/eps/venv/rca_keras.py", line 97, in <module>
rcan.save(route_save)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\keras\engine\network.py", line 1152, in save
save_model(self, filepath, overwrite, include_optimizer)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\keras\engine\saving.py", line 449, in save_wrapper
save_function(obj, filepath, overwrite, *args, **kwargs)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\keras\engine\saving.py", line 541, in save_model
_serialize_model(model, h5dict, include_optimizer)
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\keras\engine\saving.py", line 129, in _serialize_model
model_config['config'] = model.get_config()
File "C:\Users\Administrator\PycharmProjects\eps\venv\lib\site-packages\keras\engine\network.py", line 950, in get_config
return copy.deepcopy(config)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 215, in _deepcopy_list
append(deepcopy(a, memo))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 220, in _deepcopy_tuple
y = [deepcopy(a, memo) for a in x]
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 220, in <listcomp>
y = [deepcopy(a, memo) for a in x]
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 220, in _deepcopy_tuple
y = [deepcopy(a, memo) for a in x]
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 220, in <listcomp>
y = [deepcopy(a, memo) for a in x]
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\copy.py", line 169, in deepcopy
rv = reductor(4)
TypeError: can't pickle _thread.RLock objects
我搜索了其他问题,看来问题在于我使用了Lambda函数,但在其他模型上它运行良好。
有人可以告诉我为什么会发生这种情况以及我应该怎么做吗?
我的保存代码是:
route_save = route + 'rcan.hdf5'
... (Build Model and Nets/ train model )
mymodel.save(route_save)