windows 使用pytorch遇到的问题汇总

很多人都是使用mac开发的,我使用windows遇到了很多问题,这里持续记录一下

if name == ‘main‘:freeze_support()

在多线程环境中,mac不需要这行代码能够正常运行,but,windows10不能。
windows中如果没有这句,会报错.
我在使用pytorch的 Data.DataLoader的时候遇到了这个问题,在循环这个loader之前加上这个if判断就可以了
代码如下

loader = Data.DataLoader(
    dataset=torch_dataset,      # torch TensorDataset format
    batch_size=BATCH_SIZE,      # mini batch size
    shuffle=False,               # random shuffle for training
    num_workers=2,              # subprocesses for loading data
)

if __name__ == '__main__': # 使用该if正常运行
# if 1==1:# 使用该if会报错
    for epoch in range(3):   # train entire dataset 3 times
        for step, (batch_x, batch_y) in enumerate(loader):  # for each training step

错误信息如下:

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.

欢迎关注我的微信公众号:云端看大地
正准备写一个预测彩票的系列文章,敬请期待

pageTan

你可能感兴趣的:(人工智能,python,机器学习)