[代码复现]BrainGNN: Interpretable Brain Graph Neural Network for fMRI Analysis

总结一下复现 BrainGNN: Interpretable Brain Graph Neural Network for fMRI Analysis 这篇文章中遇到的问题吧

相关资源

文献:paper
代码:code
参考网页:论文复现

问题一

requirements.txt中很多@file,如下所示

scikit-learn @ file:///tmp/build/80754af9/scikit-learn_1614446682169/work
scipy @ file:///tmp/build/80754af9/scipy_1618855647378/work
seaborn @ file:///tmp/build/80754af9/seaborn_1608578541026/work

这是因为原作者在导出依赖库文件requirements.txt的时候设置出现问题了,不使用requirements.txt即可,直接在运行的时候安装要使用的库
也可以使用我导出的requirements.txt文件

问题二

在运行01-fetch_data.py和 02-process_data.py两个文件的时候,文件路径会data_folder报错,需要重新设置root_folder,相对路径不行,要用绝对路径(不过我也不知道为啥)

问题三

在运行02-process_data.py的时候会出现以下问题

AttributeError: module 'numpy' has no attribute 'object'. `np.object` was a deprecated alias for the builtin `object`. 
To avoid this error in existing code, use `object` by itself. Doing this will not modify any behavior and is safe.  
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:     
		https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. 
Did you mean: 'object_'?

这是numpy版本过高导致的

pip uninstall numpy
pip install numpy==1.23.4

问题四

torch sparse和torch scatter 可能存在不能直接pip的问题,可以去https://pytorch-geometric.com/whl/ 找自己torch对应版本的sparse和scatter(还要注意是linux还是win版本)
我是按照我的cuda版本和torch版本选的torch sparse版本 但是 还是存在以下报错:

FileNotFoundError: Could not find module 'E:\anaconda\envs\BrainGNN\Lib\site-packages\torch_sparse\_convert_cuda.pyd' (or one of its dependencies). 
Try using the full path with constructor syntax.

查了很多博客才发现还是torch版本和torch sparse版本不匹配的问题,我选的是torch-1.10.0+cu102文件中的,所以我安装torch用的命令行语句是

pip install torch==1.10.0

但是实际上应该用

pip install torch==1.10.0+cu102 torchvision==0.11.0+cu102 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html

具体语句应该参考(pytorch)[https://pytorch.org/get-started/previous-versions/]

问题五

Traceback(most recent call last):File "/home/c211/lyc/zxy/BrainGNN Pytorch-main/03-main.py", line 220, in <module>writer.add_histogram('Hist/hist_s1',s1_arr, epoch)
	File "/home/c211/anaconda3/envs/BrainG!N/lib/python3.8/site-packages/tensorboardx/writer.py", line 546, in add histogramhistogram(tag, values, bins, max_bins=max_bins), global_step, walltime)
	File "/home/c211/anaconda3/envs/BrainGNN/lib/python3.8/site-packages/tensorboardx/summary.py", line 210, in histogramhist = make_histogram(values.astype(float), bins, max_bins)
	File "/home/c211/anaconda3/envs/BrainGNN/lib/python3.8/site-packages/tensorboardX/summary.py", line 234, in make histogramcum counts = np.cumsum(np.greater(counts, 0, dtype=np.int32))
TypeError: No loop matching the specifiedsignature and casting was found for ufunc qreater

在这里插入图片描述
这个问题也是numpy版本过高的原因导致的,解决方法见问题三

问题六

AttributeError: 'TopKPooling'object has no attribute 'weight' error occurs.

找到报错的位置 发现在topkpooling的初始化过程中确实没有weight,应该是在self.select里面才有weight的属性
在这里插入图片描述
在这里插入图片描述
所以在brainnn.py中对于forward函数的返回值进行以下修改(主要是将self.pool1.weight和self.pool2.weight改为self.pool1.select.weight和self.pool2.select.weight)

return x, self.pool1.select.weight,self.pool2.select.weight, torch.sigmoid(score1).view(x.size(0),-1), torch.sigmoid(score2).view(x.size(0) -1)

解决了以上一系列问题之后 终于跑通了代码,但是第一遍跑出来的结果没有图的 只是有输出并且保存在结果中,我加了一个plt画图,

    plt.plot(tr_acc_list, label="tr_acc")
    plt.plot(val_acc_list, label="val_acc")
    plt.xlabel('epoch')
    plt.ylabel('accuracy')
    plt.title('accuracy comparison')
    plt.legend()
    plt.show()

    plt.plot(tr_loss_list, label="tr_loss")
    plt.plot(val_loss_list, label="val_loss")
    plt.xlabel('epoch')
    plt.ylabel('loss')
    plt.title('loss comparison')
    plt.legend()
    plt.show()

最终结果如下
在这里插入图片描述
在这里插入图片描述

  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值