栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

RuntimeError: An attempt has been made to start a new process before the current process...

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

RuntimeError: An attempt has been made to start a new process before the current process...

在实训时运行Pytorch表情识别代码时,出现了如下错误:
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.

这里是要把多线程任务,用单线程完成,解决方法也很简单,有如下两种:

1.去掉num_workers参数

train_dataloader = torch.utils.data.DataLoader(train_dataset,batch_size=batchsize,shuffle=True,num_workers=0)
val_dataloader = torch.utils.data.DataLoader(val_dataset,batch_size=100,shuffle=False,num_workers=0)

2.在跑epoch之前,加上if __name__=='__main__':

if __name__ == '__main__':
    for epoch in range(epochs):
        ## 训练部分
        loss = 0.0
        acc = 0.0
        n = 0
        for image,label in train_dataloader:

然后就可以正常运行了。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/701461.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号