使用Dataloader進(jìn)行多進(jìn)程數(shù)據(jù)導(dǎo)入訓(xùn)練時(shí),會(huì)因?yàn)槎噙M(jìn)程的問(wèn)題而出錯(cuò)
dataloader = DataLoader(transformed_dataset, batch_size=4,shuffle=True, num_workers=4)
其中參數(shù)num_works=表示載入數(shù)據(jù)時(shí)使用的進(jìn)程數(shù),此時(shí)如果參數(shù)的值不為0而使用多進(jìn)程時(shí)會(huì)出現(xiàn)報(bào)錯(cuò)
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.
此時(shí)在數(shù)據(jù)的調(diào)用之前加上if __name__ == '__main__':即可解決問(wèn)題
if __name__ == '__main__':#這個(gè)地方可以解決多線程的問(wèn)題
????????for i_batch, sample_batched in enumerate(dataloader):