pytorch-Dataloader多进程使用出错

2018-10-28  本文已影响0人  diandianti

使用Dataloader进行多进程数据导入训练时,会因为多进程的问题而出错

dataloader = DataLoader(transformed_dataset, batch_size=4,shuffle=True, num_workers=4)

其中参数num_works=表示载入数据时使用的进程数,此时如果参数的值不为0而使用多进程时会出现报错

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.

此时在数据的调用之前加上if __name__ == '__main__':即可解决问题

if __name__ == '__main__':#这个地方可以解决多线程的问题

        for i_batch, sample_batched in enumerate(dataloader):

上一篇下一篇

猜你喜欢

热点阅读