WuJie1010 / Facial-Expression-Recognition.Pytorch

A CNN based pytorch implementation on facial expression recognition (FER2013 and CK+), achieving 73.112% (state-of-the-art) in FER2013 and 94.64% in CK+ dataset
MIT License
1.8k stars 553 forks source link

Can the code run on a CPU-only device? #9

Closed zxfly2 closed 6 years ago

zxfly2 commented 6 years ago

Can the code run on a CPU-only device? I am getting an error when running python visualize.py on a CPU-only device.

WuJie1010 commented 6 years ago

I guess so. May be you can load the model by: pretrain = torch.load(opt.pretrain_path, map_location=lambda storage, loc: storage)

zxfly2 commented 6 years ago

Thank you for your reply. I have tried this load method before but it still can't run normally.And I got the following tips: raceback (most recent call last): File "/home/user/python_project/Python学习2/Facial-Expression-Recognition/visualize.py", line 51, in net.cuda() File "/home/user/anaconda3/envs/pytorch-python2.7/lib/python2.7/site-packages/torch/nn/modules/module.py", line 258, in cuda return self._apply(lambda t: t.cuda(device)) File "/home/user/anaconda3/envs/pytorch-python2.7/lib/python2.7/site-packages/torch/nn/modules/module.py", line 185, in _apply module._apply(fn) File "/home/user/anaconda3/envs/pytorch-python2.7/lib/python2.7/site-packages/torch/nn/modules/module.py", line 185, in _apply module._apply(fn) File "/home/user/anaconda3/envs/pytorch-python2.7/lib/python2.7/site-packages/torch/nn/modules/module.py", line 191, in _apply param.data = fn(param.data) File "/home/user/anaconda3/envs/pytorch-python2.7/lib/python2.7/site-packages/torch/nn/modules/module.py", line 258, in return self._apply(lambda t: t.cuda(device)) RuntimeError: Cannot initialize CUDA without ATen_cuda library. PyTorch splits its backend into two shared libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some reason. The CUDA library MUST be loaded, EVEN IF you don't directly use any symbols from the CUDA library! One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many dynamic linkers will delete dynamic library dependencies if you don't depend on any of their symbols. You can check if this has occurred by using ldd on your binary to see if there is a dependency on *_cuda.so library.

Process finished with exit code 1

Have you successfully run on a CPU-only device before?

zxfly2 commented 6 years ago

Thank you for your advice, my problem has been solved.After commenting out the code with .cuda( ), I can run successfully on a CPU-only device.

dingmingdu commented 6 years ago

Thank you for your advice, my problem has been solved.After commenting out the code with .cuda( ), I can run successfully on a CPU-only device.

could you tell me how do you realize it specifically?

zxfly2 commented 6 years ago

Just comment out the code with .cuda( ) in viusalize.py file,such as:

net = VGG('VGG19') checkpoint = torch.load(os.path.join('FER2013_VGG19', 'PrivateTest_model.t7')) net.load_state_dict(checkpoint['net']) net.cuda() net.eval()

you can comment out the net.cuda( )