尝试编译并安装PyTorch的C++扩展:EMD Loss (Earth Mover’s Distance 动土距离),GitHub链接:https://github.com/meder411/PyTorch-EMDLoss
本人使用Ubuntu 16.04,PyTorch 1.7 + CUDA 11,但由于原文件是用PyTorch 1.0写的,所以直接运行python setup.py install的话,ninja编译器会报错。报错很长,这里贴几个关键词:
(中间)
FAILED: /xxxxx/PyTorch-EMDLoss-master/build/temp.linux-x86_64-3.6/pkg/src/emd.o
(结尾处)
File "/xxxxx/anaconda3/envs/pcrnet/lib/python3.6/subprocess.py", line 438, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1. The above exception was the direct cause of the following exception:
raise RuntimeError(message) from e RuntimeError: Error compiling objects for extension
解决方案:在所有.h、.cu、.cuh文件开头define处加上3行,即可适应高版本PyTorch:
#ifndef AT_CHECK #define AT_CHECK TORCH_CHECK #endif
具体可参考https://github.com/oIi123/PyTorch-EMDLoss



