MXNet的gluon报The "freeze_support()" line can be omitted if the program

详细错误提示

Traceback (most recent call last):
  File "", line 1, in 
Traceback (most recent call last):
  File "D:/python_workspace/mxnet_example/Neural_NetWork.py", line 44, in 
    train_data = gluon.data.DataLoader(fashion_data,batch_size=batch_size,shuffle=True,num_workers=4)
  File "F:\software\Anaconda\envs\mxnet\lib\site-packages\mxnet\gluon\data\dataloader.py", line 550, in __init__
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\spawn.py", line 105, in spawn_main
    self._num_workers, initializer=_worker_initializer, initargs=[self._dataset])
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\context.py", line 119, in Pool
    exitcode = _main(fd)
    context=self.get_context())
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\spawn.py", line 114, in _main
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\pool.py", line 174, in __init__
    self._repopulate_pool()
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\pool.py", line 239, in _repopulate_pool
    prepare(preparation_data)
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\spawn.py", line 225, in prepare
    w.start()
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\process.py", line 105, in start
    _fixup_main_from_path(data['init_main_from_path'])
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
    self._popen = self._Popen(self)
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
    run_name="__mp_main__")
  File "F:\software\Anaconda\envs\mxnet\lib\runpy.py", line 263, in run_path
    reduction.dump(process_obj, to_child)
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
BrokenPipeError: [Errno 32] Broken pipe
    pkg_name=pkg_name, script_name=fname)
  File "F:\software\Anaconda\envs\mxnet\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "F:\software\Anaconda\envs\mxnet\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\python_workspace\mxnet_example\Neural_NetWork.py", line 44, in 
    train_data = gluon.data.DataLoader(fashion_data,batch_size=batch_size,shuffle=True,num_workers=4)
  File "F:\software\Anaconda\envs\mxnet\lib\site-packages\mxnet\gluon\data\dataloader.py", line 550, in __init__
    self._num_workers, initializer=_worker_initializer, initargs=[self._dataset])
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\context.py", line 119, in Pool
    context=self.get_context())
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\pool.py", line 174, in __init__
    self._repopulate_pool()
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\pool.py", line 239, in _repopulate_pool
    w.start()
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\popen_spawn_win32.py", line 33, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
    _check_not_importing_main()
  File "F:\software\Anaconda\envs\mxnet\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
    is not going to be frozen to produce an executable.''')
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.

定位提示报错代码

train_data = gluon.data.DataLoader(fashion_data,batch_size=batch_size,shuffle=True,num_workers=4)

错误原因分析

从错误看来是由于多线程的原因导致的,官方解释说在Windows不支持gluon.data.DataLoader中的num_workers>0的设置,所以将num_workers设置为0就好了

官方说明如下

链接:http://mxnet.apache.org/versions/1.2.1/_modules/mxnet/gluon/data/dataloader.html

num_workers : int, default 0
        The number of multiprocessing workers to use for data preprocessing.
        `num_workers > 0` is not supported on Windows yet.

 

参考链接:https://discuss.gluon.ai/t/topic/6839/16

你可能感兴趣的:(mxnet修炼之路)