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

AttributeError: Can't pickle local object 'checkpoint.begin_background.<locals>.bg_target' #105

Closed
DirtyLI opened this issue Jan 2, 2019 · 2 comments

Comments

@DirtyLI
Copy link

DirtyLI commented Jan 2, 2019

HI
I will ask you a new question.
When i tried to use this code to test my own images, one error happened:
matplotlib.use('Agg')
Making model...
Download the model

Evaluation:
Traceback (most recent call last):

File "", line 1, in
runfile('F:/代码/EDSR-PyTorch-master/src/main.py', args='--data_test Demo --scale 4 --pre_train download --test_only --save_results', wdir='F:/代码/EDSR-PyTorch-master/src')

File "F:\anaconda\conda\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
execfile(filename, namespace)

File "F:\anaconda\conda\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "F:/代码/EDSR-PyTorch-master/src/main.py", line 24, in
while not t.terminate():

File "F:\代码\EDSR-PyTorch-master\src\trainer.py", line 139, in terminate
self.test()

File "F:\代码\EDSR-PyTorch-master\src\trainer.py", line 83, in test
if self.args.save_results: self.ckp.begin_background()

File "F:\代码\EDSR-PyTorch-master\src\utility.py", line 141, in begin_background
for p in self.process: p.start()

File "F:\anaconda\conda\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)

File "F:\anaconda\conda\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)

File "F:\anaconda\conda\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)

File "F:\anaconda\conda\lib\multiprocessing\popen_spawn_win32.py", line 65, in init
reduction.dump(process_obj, to_child)

File "F:\anaconda\conda\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)

AttributeError: Can't pickle local object 'checkpoint.begin_background..bg_target'

@sanghyun-son
Copy link
Owner

Hi.

It seems there are some conflicts between multiprocessing and your system. Remove this and these lines to disable multiprocessing.

Thank you

@Drakael
Copy link

Drakael commented Apr 30, 2019

Hello,
I had the same error and worked it around by taking out the bg_target method inside begin_background() and making it a static method of the checkpoint class (in src/utility.py around line 130)

Code sample :

@staticmethod
def bg_target(queue):
    while True:
        if not queue.empty():
            filename, tensor = queue.get()
            if filename is None: break
            imageio.imwrite(filename, tensor.numpy())

def begin_background(self):
    self.queue = Queue()
    
    self.process = [
        Process(target=self.bg_target, args=(self.queue,)) \
        for _ in range(self.n_processes)
    ]
    
    for p in self.process: p.start()

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

No branches or pull requests

3 participants