Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

TypeError: can't pickle _thread.RLock objects #114

Closed
gkrislara opened this issue Mar 27, 2020 · 2 comments
Closed

TypeError: can't pickle _thread.RLock objects #114

gkrislara opened this issue Mar 27, 2020 · 2 comments

Comments

@gkrislara
Copy link

I am trying to save json file using model.to_json() for rrdn model
I have modified the class to input only patch size
dense=RRDN(patch_size=patch_size) # model weights are loaded here
model=dense.model
with open(os.path.join('RRDN_40x40_C4D30G32G032T10x4.json'), 'w') as f:
f.write(model.to_json())

While executing the program I get the following error:
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/copy.py", line 150, in deepcopy
y = copier(x, memo)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/copy.py", line 169, in deepcopy
rv = reductor(4)
TypeError: can't pickle _thread.RLock objects

I referred #107 but still I am unable to solve the issue

@gkrislara
Copy link
Author

solved by using local variables for lambda functions instead of using class init attributes directly

def _RRDB(self, input_layer, t):
x = input_layer
beta=self.beta #THIS SOLVED THE ISSUE
for d in range(1, self.D + 1):
LFF = self._dense_block(x, d, t)
LFF_beta = Lambda(lambda x: x * beta)(LFF) #self.beta was used before
x = Add(name='LRL_%d_%d' % (t, d))([x, LFF_beta])
x = Lambda(lambda x: x * beta)(x) #self.beta was used before
x = Add(name='RRDB_%d_out' % (t))([input_layer, x])
return x
likewise in _pixel_shuffle() replaced self.scale with local variable scale

@cfrancesco
Copy link
Collaborator

@gkrislara Interesting! It could be that is missing the get_config method:
https://www.tensorflow.org/tutorials/keras/save_and_load#saving_custom_objects

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants