likyoo / Siam-NestedUNet

The pytorch implementation for "SNUNet-CD: A Densely Connected Siamese Network for Change Detection of VHR Images"
MIT License
246 stars 59 forks source link

freeze_support() on Windows Python 3.8 #3

Closed loviji closed 3 years ago

loviji commented 3 years ago

Hello, I have checked this project on Windows 10 with Python 3.8, and get an error.

PS S:\gis\siameseDetect\Siam-NestedUNet> python train.py
  File "train.py", line 68
    for epoch in range(opt.epochs):
    ^
IndentationError: expected an indented block
PS S:\gis\siameseDetect\Siam-NestedUNet> python train.py
INFO:root:GPU AVAILABLE? False
INFO:root:STARTING Dataset Creation
INFO:root:STARTING Dataloading
INFO:root:LOADING Model
INFO:root:STARTING training
INFO:root:SET model mode to train!
  0%|                                                                        | 0/188 [00:00<?, ?it/s]INFO:root:GPU AVAILABLE? False
INFO:root:STARTING Dataset Creation
INFO:root:STARTING Dataloading
INFO:root:LOADING Model
INFO:root:STARTING training
INFO:root:SET model mode to train!
  0%|                                                                        | 0/188 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python38\lib\multiprocessing\spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "C:\Python38\lib\multiprocessing\spawn.py", line 125, in _main
    prepare(preparation_data)
  File "C:\Python38\lib\multiprocessing\spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "C:\Python38\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "C:\Python38\lib\runpy.py", line 265, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "C:\Python38\lib\runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "C:\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "S:\gis\siameseDetect\Siam-NestedUNet\train.py", line 80, in <module>
    for batch_img1, batch_img2, labels in tbar:
  File "C:\Python38\lib\site-packages\tqdm\std.py", line 1166, in __iter__
    for obj in iterable:
  File "C:\Python38\lib\site-packages\torch\utils\data\dataloader.py", line 279, in __iter__
    return _MultiProcessingDataLoaderIter(self)
  File "C:\Python38\lib\site-packages\torch\utils\data\dataloader.py", line 719, in __init__
    w.start()
  File "C:\Python38\lib\multiprocessing\process.py", line 121, in start
    self._popen = self._Popen(self)
  File "C:\Python38\lib\multiprocessing\context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Python38\lib\multiprocessing\context.py", line 327, in _Popen
    return Popen(process_obj)
  File "C:\Python38\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\Python38\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "C:\Python38\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

number of gpus setted to 0 on metadata.json file, because I've not CUDA torch and torchvision installed like this. _pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html_

If this code runned and tested in non-Windows environment, please share tested operating system info, if it's possible.

likyoo commented 3 years ago

Hi @loviji , sorry, we did not test the code on the CPU under Windows. Our test environment is: Linux/ PyTorch =1.4.0/ Python =3.6/1*nvidia-v100 (64G). And about this error, you may use if name == 'main:' in Windows (reference) or run this code in Linux.

loviji commented 3 years ago

Hi, @likyoo for your assist and detailed answer. I'm going to test this code in Linux with CPU, and will share results.

fpan98 commented 3 years ago

I got the same error and fixed it with adding the following line in the eval.py after the import section: if name == 'main':