运行个性化联邦项目

一、首次直接运行 使用pcas数据集

PersonalizedFL-main   针对fedclip项目文件夹

1、选好torch环境 python=3.8

2、根据requirements.txt下载相关包

运行  pip install -r .\requirements.txt

 3、fed_at_clip.py文件包报红

使用命令下载pip install utils -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

 安装不对 ,这是从文件中导入的,

应该改为导入的完整目录

4、安装的clip有问题,不能直接pip安装

 -在此卸载clip:pip install clip

-通过使用openAI提供的github安装源安装

pip install ftfy regex tqdm
pip install git+https://github.com/openai/CLIP.git

-再报错: error: RPC failed; curl 28 Recv failure: Connection was reset
                  fatal: expected flush after ref listing
                  error: subprocess-exited-with-error

-输入命令:git config --global http.sslVerify "false"

-再下载clip 成功

 5、小绿三角运行

在下载

6、 报错 AssertionError: Torch not compiled with CUDA enabled

将cuda改为cpu,本电脑没有装cuda

在models.py里,device=“cpu”

 7、数据集找不到错误,因为没有下载数据集

 去https://wjdcloud.blob.core.windows.net/dataset/PACS.zip下载PACS数据集

另外,昨天在命令行使用wget下载,发现下完之后找不到该文件,不知道下载到哪里了

数据集那里改了下地址,是org.root_dir 没有定义

后续 读到了在fed_at_clip中,有定义root_dir的参数,在此处修改即可

8、pip install git+https://github.com/openai/CLIP.git报错没有git

在该pytorch下conda Install git 就可,不能pip install git

9、配pytorch环境,选择

 

10、pip安装requirement文件报错  ERROR: Could not find a version that satisfies the requirement numpy==1.22.0 (from versions: none) E

 使用镜像源安装,即可,都手动安装

pip install numpy -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

11、下载的clip模型

二、第二次运行 运行其他baseline项目,使用covid19数据集

1、运行Fed》main.py

2、报错:AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
是因为np.int 在 NumPy 1.20 中已弃用,在 NumPy 1.24 中已删除

改:在datasplit.py中将np.int改为np.int_即可

 3、报错ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (15,) + inhomogeneous part.

改:更换了numpy版本,从原来的numpy1.24.3替换为numpy1.22.0

pip uninstall numpy

再安装一下pip install numpy==1.22.0 成功

4、报了个警告:VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  tmparr = np.array(tmparr)

可见弃用警告:不推荐使用从参差不齐的嵌套序列(这是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建 ndarray。如果要执行此操作,则必须在创建 ndarray 时指定“dtype=object”。
  tmparr = np.array(tmparr)

不过能正常训练

5、发现一个事情fed_at_clip.py的当前目录 ./ 是指fedclip

三、使用colab在线GPU运行项目

1、首先在云端谷歌硬盘https://drive.google.com/drive/my-drive中将自己的项目文件夹上传上去

2、要关联Google Colaboratory

关联成功之后

3、在Colaboratory官网上 https://colab.research.google.com/上先装载谷歌云端硬盘

装载成功就可以在该处看到自己的云盘文件夹

4、然后新建笔记本

5、重新装载一下云端硬盘

6、修改设置,硬件加速器改为GPU

7、在命令行进入文件夹目录

cd /content/drive/MyDrive/fedclip

然后安装Clip:

pip install git+https://github.com/openai/CLIP.git

然后运行

%run ./methods/fed_at_clip.py --dataset CXR8 --mode FedAtImg --test_envs 1 --iters 5 --wk_iters 1 --lr 5e-05

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 完全去中心化的联邦学习实例python源码+项目说明+模型+数据.zip ## 一、代码架构 1. configuration:存放配置文件,在配置文件中分为**横向联邦**与**纵向联邦**配置,可分开配置与运行 ![image-20230806184146406](./img/configuration.png) 2. data:存放数据加载与处理代码 3. model:存放模型 4. train:存放训练代码 5. train/res:存放训练结果图,所有模型训练后的结果图会存放在该目录下 6. utils:存放工具函数 7. img:存放readme图片 ## 二、代码详解 ### (一) 横向联邦 #### 1 数据集 选用 `FashionMNIST` 数据集,训练集涵盖60000张服饰图片,测试集涵盖10000张服饰图片,共有10种类别 ![image-20230806184146406](./img/image-20230806184146406.png) #### 2 参与训练客户端 1. 在代码中,创建n个不同的client对象,简单模拟n个客户端(客户端数量可在配置文件中配置) 2. 客户端以**环形**方式连接,[0->1->2->3->...->n->0] 3. 客户端之间信息传输以函数调用形式体现,**但实际情况下,不同客户端之间数据传输应依靠网络IO,如何降低通信开销是后面需要注意的地方** #### 3.数据集获取与划分 ......

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值