When using linux
the training neural network, the normal training code will not report any errors, but when debugging, it can only jump to the breakpoint and cannot run later, but it is ok. I have encountered it too many times. Why windows
? Will this problem occur? Today I finally solved this problem, record it.
We can use multi-threading during linux
training. In the following code num_workers=8
, we know that windows
multi-threading is not supported when training the network, so when using windows
training, our thread settings here are 0
, that is, whether you are debugging or Running him directly is a thread 0
. But linux
it supports multi-threading. Usually we set the number of threads to be greater than 1
. But there will be problems when debugging. My Pycharm
debugging interface only supports the main process, and it cannot be used after the thread is opened.
train_data_loader = torch.utils.data.DataLoader(train_dataset,
batch_size=batch_size,
shuffle=True,
num_workers=8,
collate_fn=train_dataset.collate_fn,
drop_last=drop_last)
The solution is very simple. When running directly, you don’t need to worry about the number of threads, but it is enough to set it to when debugging 0
.
train_data_loader = torch.utils.data.DataLoader(train_dataset,
batch_size=batch_size,
shuffle=True,
num_workers=0,
collate_fn=train_dataset.collate_fn,