video-classification
video-classification copied to clipboard
RuntimeError: freeze_support() on Windows
Hello, thanks a lot for your great job which is very excellent and inspires me a lot. Now I am trying to run your code UCF101_CRNN.py on a Windows PC but facing a Runtime problem. I tried weeks to fix this problem but still failed. So I am wondering if you could please kindly help me.
When I was simply running UCF101_CRNN.py, I got this error:
C:\Anaconda3\envs\pytorch1\python.exe D:/LSTM/study/video-classification-master/CRNN/UCF101_CRNN.py
C:\Anaconda3\envs\pytorch1\lib\site-packages\sklearn\preprocessing_encoders.py:415: FutureWarning: The handling of integer data will change in version 0.22. Currently, the categories are determined based on the range [0, max(values)], while in the future they will be determined based on the unique values.
If you want the future behaviour and silence this warning, you can specify "categories='auto'".
In case you used a LabelEncoder before this OneHotEncoder to convert the categories to integers, then you can now use the OneHotEncoder directly.
warnings.warn(msg, FutureWarning)
C:\Anaconda3\envs\pytorch1\lib\site-packages\sklearn\preprocessing_encoders.py:415: FutureWarning: The handling of integer data will change in version 0.22. Currently, the categories are determined based on the range [0, max(values)], while in the future they will be determined based on the unique values.
If you want the future behaviour and silence this warning, you can specify "categories='auto'".
In case you used a LabelEncoder before this OneHotEncoder to convert the categories to integers, then you can now use the OneHotEncoder directly.
warnings.warn(msg, FutureWarning)
Traceback (most recent call last):
File "
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.
Process finished with exit code 1
I searched on the Internet and it seemed that the problem is caused by that Windows doesn't not support fork multiprocessing. Then according to https://github.com/pytorch/pytorch/issues/5858, I added these codes at the beginning of UCF101_CRNN.py:
def run(): torch.multiprocessing.freeze_support() print('loop')
if name == 'main': run()
And the modified code becomes into:
import os import numpy as np import torch import torch.nn as nn import torch.nn.functional as F import torchvision.models as models import torchvision.transforms as transforms import torch.utils.data as data import torchvision from torch.autograd import Variable import matplotlib.pyplot as plt from functions import * from sklearn.model_selection import train_test_split from sklearn.preprocessing import OneHotEncoder, LabelEncoder from sklearn.metrics import accuracy_score import pickle
def run(): torch.multiprocessing.freeze_support() print('loop')
if name == 'main': run()
data_path = "D:\ucf\jpegs_256" # define UCF-101 RGB data path action_name_path = './UCF101actions.pkl' save_model_path = "./CRNN_ckpt/"
CNN_fc_hidden1, CNN_fc_hidden2 = 1024, 768 CNN_embed_dim = 512 # latent dim extracted by 2D CNN img_x, img_y = 256, 342 # resize video 2d frame size dropout_p = 0.0 # dropout probability
RNN_hidden_layers = 3 RNN_hidden_nodes = 512 RNN_FC_dim = 256
... all other lines ...
But I still have the same problem:
C:\Anaconda3\envs\pytorch1\python.exe D:/LSTM/study/video-classification-master/CRNN/UCF101_CRNN.py
loop
C:\Anaconda3\envs\pytorch1\lib\site-packages\sklearn\preprocessing_encoders.py:415: FutureWarning: The handling of integer data will change in version 0.22. Currently, the categories are determined based on the range [0, max(values)], while in the future they will be determined based on the unique values.
If you want the future behaviour and silence this warning, you can specify "categories='auto'".
In case you used a LabelEncoder before this OneHotEncoder to convert the categories to integers, then you can now use the OneHotEncoder directly.
warnings.warn(msg, FutureWarning)
C:\Anaconda3\envs\pytorch1\lib\site-packages\sklearn\preprocessing_encoders.py:415: FutureWarning: The handling of integer data will change in version 0.22. Currently, the categories are determined based on the range [0, max(values)], while in the future they will be determined based on the unique values.
If you want the future behaviour and silence this warning, you can specify "categories='auto'".
In case you used a LabelEncoder before this OneHotEncoder to convert the categories to integers, then you can now use the OneHotEncoder directly.
warnings.warn(msg, FutureWarning)
Traceback (most recent call last):
File "
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.
Process finished with exit code 1
Could you please kindly help me fix this problem?
Hi, thank you for reporting a problem running on Windows. Long time ago I seemed to notice there's a difference running Pytorch codes on Windows & Linux. Since now I no longer have a Windows machine, I am afraid that I am not able to reproduce your problem.
May I suggest that you remove (or comment out) the part parallelizing to multiple GPUs? eg. in CRNN/UCF101_CRNN.py, delete all lines between 192 and 195
Hi, I got the same problem but just in the ResNetCRNN_check_prediction.py file. BUT with the help of a friend I found the solution on github after long time searching the internet:
Windows doesn't use fork, but spawn which needs the code to be changed a bit to not run the code multiple times at once.
After all import commands you need to define the whole code as the main() function _... from functions import *
def main(): # set path data_path = "C:/Users/erik.ackermann/LSTM_Data/jpegs_256" # define UCF-101 RGB data path action_name_path = "./UCF101actions.pkl" ... print('video prediction finished!')
if name == 'main': main()_
More explanation can be found in the Windows FAQ to pytorch
The solution was reported by peterjc123 on github #7485
I hope that still helps somebody.