When running the Pytorch expression recognition code during hands-on training, the following error occurred:
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.
Here is to take multi-threaded tasks, using a single thread to complete, the solution is also very simple, there are the following two.
1. remove the num_workers parameter
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. Add if __name__=='__main__'
before epoch
:
if __name__ == '__main__': for epoch in range(epochs): loss = 0.0 acc = 0.0 n = 0 for image,label in train_dataloader:
Then it can run normally.
Read More:
- [Solved] Windows Nginx Startup Error: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket
- [Solved] Redisson distributed lock error: attempt to unlock lock, not locked by current thread by node id
- HTTP Error 500.30 – ANCM In-Process Start Failure
- [Solved] IDEA Start Project Error: Abnormal build process termination:Could not create the Java Virtual Machine.
- Conda create New environment Error: An unexpected error has occurred. Conda has prepared the above report.
- Ubutnu Qt Unable to start process Error: “make“ -f ‘ /usr/bin/ld: cannot find -lGL collect2: error: ld returned 1 exit sta
- Docker run Error: container_linux.go:235: starting container process caused “process_linux.go:258: appl
- When installing zookeeper, you can view the process start, but the status display error: Error contacting service. It is probably not running
- [Solved] Postgres Start Error: Job for postgresql.service failed because the control process exited with error code.
- [Solved] Hadoop Start NameNode Error: ERROR: Cannot set priority of namenode process 2639
- [Solved] MindSpore Error: “RuntimeError: Unable to data from Generator..”
- PIP Fatal error in launcher: Unable to create process using
- The showdialog() method in thread/threading. Timer/task reported an error: “before ole can be called, the current thread must be set to single thread unit (STA) mode.”
- [Solved] zookeeper Startup Error: already running as process
- How to Solve “Status bar could not find cached time string image. Rendering in-process.” in Xcode
- [Solved] RuntimeError: each element in list of batch should be of equal size
- Kill Tomcat process in windows and Linux environment (solve the problem of other ports being occupied)
- [Solved] Startservice error: Process: com.example.provider, PID: 31612
- [Solved] ERROR–Unable to process Jar entry [module-info.class] from Jar
- [Solved] error: Raw kernel process exited code: 3221226505