Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

gkrislara opened this issue Mar 27, 2020 · 2 comments

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

gkrislara opened this issue Mar 27, 2020 · 2 comments


Copy link

gkrislara commented Mar 27, 2020

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
with open(os.path.join('RRDN_40x40_C4D30G32G032T10x4.json'), 'w') as f:

While executing the program I get the following error:
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/", line 150, in deepcopy
y = copier(x, memo)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/", 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

Copy link

gkrislara commented Mar 27, 2020

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

Copy link

cfrancesco commented Mar 27, 2020

@gkrislara Interesting! It could be that is missing the get_config method:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants