这篇博客也就是简单记录一下。由于工作需要,想尝试一下这篇论文的工作:
https://github.com/ljj-cyber/TopoGDN
发现很多人真是开源不用脑子,自己也不测试一下(当然不是针对这个作者),只是感觉大家都太不认真了(草台班子太严重)。总结一下遇到的问题:
首先,看作者这里介绍:
To install this project, you need to install the following Python libraries:
pip install torch==1.13.1+cu117 pip install torch-cluster==1.6.0+pt113cu116 pip install torch-geometric==1.7.1 pip install torch-scatter==2.1.0+pt113cu116 pip install torch-sparse==0.6.15+pt113cu116 pip install torch-spline-conv==1.2.1+pt113cu116 pip install pyg-lib==0.2.0+pt113cu116
可以猜出来其环境是PyTorch 1.13.1,CUDA是11.7。首先吐槽一点,难道不应该是在conda之类的虚拟环境里安装吗?我首先创建一个虚拟环境:
conda create -n GDN python=3.7
至于为什么是Python 3.7,等会解释。接下来进入到这个环境中,运行:
conda install cuda -c nvidia/label/cuda-11.7.0
来安装CUDA,参考这里:Windows 11怎样在不同Anaconda环境中安装不同版本的CUDA_anaconda不同环境安装不同cuda-CSDN博客
接下来安装PyTorch:Previous PyTorch Versions | PyTorch:
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia
安装好PyTorch之后就可以尝试运行:
pip install torch-cluster==1.6.0+pt113cu116
另外吐槽一点,上面不是CUDA 11.7吗?为啥后面都改成CUDA 11.6对应的版本了,个人感觉11.7应该是可以的。
结果报下面的错误:
ERROR: Ignored the following versions that require a different python version: 1.6.2 Requires-Python >=3.8; 1.6.3 Requires-Python >=3.8
ERROR: Could not find a version that satisfies the requirement torch-cluster==1.6.0+pt113cu116 (from versions: 0.1.1, 0.2.3, 0.2.4, 1.0.1, 1.0.3, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.3.0, 1.4.0, 1.4.1, 1.4.2, 1.4.3a1, 1.4.3, 1.4.4, 1.4.5, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.5.9, 1.6.0, 1.6.1)
ERROR: No matching distribution found for torch-cluster==1.6.0+pt113cu116
这些作者,自己都不在一个clean的环境里测试一下吗??
解决方法我在上一篇博客里说了:pip报类似No matching distribution found for torch-scatter==2.1.0+pt113cu116的一种解决方案_error: no matching distribution found for jieba-CSDN博客
pip install torch-geometric==1.7.1
这个是可以运行的,但其他的lib,可以从上面博客里说的链接里下载whl文件,然后运行:
pip install torch_cluster-1.6.0+pt113cu117-cp37-cp37m-linux_x86_64.whl
pip install torch_scatter-2.1.0+pt113cu117-cp37-cp37m-linux_x86_64.whl
pip install torch_sparse-0.6.15+pt113cu117-cp37-cp37m-linux_x86_64.whl
pip install torch_spline_conv-1.2.1+pt113cu117-cp37-cp37m-linux_x86_64.whl
pip install pyg_lib-0.2.0+pt113cu117-cp37-cp37m-linux_x86_64.whl
本想着这下就搞定了:
git clone https://github.com/ljj-cyber/TopoGDN.git
cd TopoGDN
python main.py --dataset msl
还是先报了一个(呵呵呵呵呵):
ModuleNotFoundError: No module named 'matplotlib'
这个简单,但是下一个报错我就不知道怎么处理了:
ImportError: /TopoGDN/torch_persistent_homology/persistent_homology_cpu.cpython-37m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory
这个错嘛,感觉是少了这样一个.so的文件,也就是从这里,我们可以看出来作者对应的python版本是3.7,大家可以搜一下自己系统里的对应文件:
find / -type f -name "*cpython-37m-x86_64-linux-gnu.so"
可以看到有很多(如果有Python 3.7环境的话)。
但是找不到上面这个.so文件,所以我们需要自己生成一下。仔细看一下作者的文件夹,有torch_persistent_homology和repo/torch_persistent_homology两个文件夹,但是这两个文件夹作者完全没有解释啊。下面简单总结一下解决这个问题的步骤,不想了解的朋友可以直接看后面的结论了:
---------------------------------------------------------------------------------------------
首先,直接在google里搜索“persistent_homology_cpu”,可以看到相关的网页很少,但是第一个GitHub上的讨论的确是相关的:https://github.com/BorgwardtLab/TOGL/issues/6
顺着这里的讨论,可以看到这个repo:https://github.com/ExpectationMax/torch_persistent_homology
从上面的讨论可知,应该编译一下上面这个repo就可以得到缺少的这个.so文件,可是有两个问题, 一是上面这个repo缺少setup.py文件啊(参考这里的介绍:将Python脚本编译为so文件的方法,并实现调用_python main 编译成.so-CSDN博客);第二个问题是,上面这个repo竟然把文件名写错了:perisistent_homology_cpu.cpp ——多了一个i,搞笑的是,TopoGDN的作者还在这里提醒原作者:There is a typo in your filename · Issue #3 · ExpectationMax/torch_persistent_homology · GitHub
呵呵呵呵呵,这些开源的哥们自己都不看看吗?这么弱智的错误也会犯?
关于第一个问题,虽然上面这个repo没有setup.py,但是TopoGDN的作者实际上是加上了setup.py的(虽然自己一句也没提起什么作用)。
---------------------------------------------------------------------------------------------
根据上面的讨论,其实解决方法就有了:
1. clone上面这个repo:
git clone https://github.com/ExpectationMax/torch_persistent_homology.git
2. 把TopoGDN里的setup文件拷贝到这个repo目录下。
3. 将这个repo里的cpp文件名纠正一下,也就是删掉i,变成:persistent_homology_cpu.cpp
4. 运行:
python setup.py build_ext --inplace
(做完这些步骤真是醉了,为啥开源的时候就不能有点责任心,自己在一个干净的环境上配置一下?非得让人猜究竟怎么做)
(如果报缺少gcc之类的错,可以参考上面那篇博客)做完这一切,我们就在torch_persistent_homology/build/lib.linux-x86_64-cpython-37/torch_persistent_homology/persistent_homology_cpu.cpython-37m-x86_64-linux-gnu.so 目录底下得到了这个.so文件,那么把这个so文件拷贝到刚才报错的路径下,然后再运行:
python main.py --dataset msl
结果还是报错:
ModuleNotFoundError: No module named 'topognn'
呵呵呵呵呵呵呵,这是开源了个毛线啊。
仔细看了一下,把model/topoPooling.py文件里的
import topognn.coord_transforms as coord_transforms
换成:
from . import coord_transforms
即可。再运行一次,报错:
ModuleNotFoundError: No module named 'torchsummary'
再把没装的lib都装一下:
pip install torchsummary
pip install torchstat
结果竟然还是报错:
main.py: error: unrecognized arguments: --dataset msl
看到这里我无了个大语,原来要运行:
python main.py -dataset msl
然后就可以看到结果了。不得不说,这个repo的质量也太差了,呵呵呵。
就简单记录这么多,想着有朋友可能会遇到类似的问题(不一定是一样的过程,但是解决思路是相似的),就简单记录一下。再次呼吁,在论文里宣称自己开源的作者们,用点心吧!