当前位置:   article > 正文

使用MistNet在COCO128数据集上协作训练Yolo-v5

使用MistNet在COCO128数据集上协作训练Yolo-v5

本案例介绍如何在MNIST手写数字分类场景中,使用名为MistNet的聚合算法训练联邦学习作业。数据分散在不同的地方(如边缘节点、摄像头等),由于数据隐私和带宽的原因,无法在服务器上聚合。因此,我们不能将所有数据都用于训练。在某些情况下,边缘节点的计算资源有限,甚至没有训练能力。边缘无法从训练过程中获取更新的权重。因此,传统算法(例如,联合平均算法)通常聚合由不同边缘客户端训练的更新权重,在这种情况下无法工作。MistNet 被提议解决这个问题。

MistNet 将 DNN 模型分为两部分,边缘侧的轻量级特征提取器用于从原始数据生成有意义的特征,以及包含云中最多模型层的分类器,用于针对特定任务进行迭代训练。MistNet 实现了可接受的模型效用,同时大大减少了已发布的中间功能造成的隐私泄露。

物体检测实验

假设有两个边缘节点和一个云节点。由于隐私问题,边缘节点上的数据无法迁移到云中。基于此场景,我们将演示mnist示例

安装Sedna

准备数据集

Create data interface for EDGE1_NODE.

mkdir -p /data/1
cd /data/1
wget https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip
unzip coco128.zip -d COCO

Create data interface for EDGE2_NODE.

准备镜像

此示例使用以下映像:
聚合工作器:kubeedge/sedna-example-federated-learning-mistnet-yolo-aggregator:v0.4.0
训练工作器:kubeedge/sedna-example-federated-learning-mistnet-yolo-client:v0.4.0
这些图像是由脚本build_images.sh生成的。

创建联合学习作业

创建用于$EDGE1_NODE和$EDGE2_NODE的数据集

  1. kubectl create -f - <<EOF
  2. apiVersion: sedna.io/v1alpha1
  3. kind: Dataset
  4. metadata:
  5. name: "coco-dataset-1"
  6. spec:
  7. url: "/data/1/COCO"
  8. format: "dir"
  9. nodeName: kubeedge1
  10. EOF
  1. kubectl create -f - <<EOF
  2. apiVersion: sedna.io/v1alpha1
  3. kind: Dataset
  4. metadata:
  5. name: "coco-dataset-2"
  6. spec:
  7. url: "/data/2/COCO"
  8. format: "dir"
  9. nodeName: kubeedge2
  10. EOF

创建模型
在 $EDGE 1_NODE 和 $EDGE 2_NODE 中创建目录 /model 和 /pretrained 。

mkdir -p /model
mkdir -p /pretrained

在$CLOUD_NODE主机上创建目录/model和/pretrained(下载链接在这里)

  1. # on the cloud side
  2. mkdir -p /model
  3. mkdir -p /pretrained
  4. cd /pretrained
  5. wget https://kubeedge.obs.cn-north-1.myhuaweicloud.com/examples/yolov5_coco128_mistnet/yolov5.pth

创建模型

  1. kubectl create -f - <<EOF
  2. apiVersion: sedna.io/v1alpha1
  3. kind: Model
  4. metadata:
  5. name: "yolo-v5-model"
  6. spec:
  7. url: "/model/yolov5.pth"
  8. format: "pth"
  9. EOF
  10. kubectl create -f - <<EOF
  11. apiVersion: sedna.io/v1alpha1
  12. kind: Model
  13. metadata:
  14. name: "yolo-v5-pretrained-model"
  15. spec:
  16. url: "/pretrained/yolov5.pth"
  17. format: "pth"
  18. EOF

使用您的S3用户凭据创建一个密钥。(可选)

开始联邦学习

  1. kubectl create -f - <<EOF
  2. apiVersion: sedna.io/v1alpha1
  3. kind: FederatedLearningJob
  4. metadata:
  5. name: yolo-v5
  6. spec:
  7. pretrainedModel: # option
  8. name: "yolo-v5-pretrained-model"
  9. transmitter: # option
  10. ws: { } # option, by default
  11. s3: # optional, but at least one
  12. aggDataPath: "s3://sedna/fl/aggregation_data"
  13. credentialName: mysecret
  14. aggregationWorker:
  15. model:
  16. name: "yolo-v5-model"
  17. template:
  18. spec:
  19. nodeName: $CLOUD_NODE
  20. containers:
  21. - image: kubeedge/sedna-example-federated-learning-mistnet-yolo-aggregator:v0.4.0
  22. name: agg-worker
  23. imagePullPolicy: IfNotPresent
  24. env: # user defined environments
  25. - name: "cut_layer"
  26. value: "4"
  27. - name: "epsilon"
  28. value: "100"
  29. - name: "aggregation_algorithm"
  30. value: "mistnet"
  31. - name: "batch_size"
  32. value: "32"
  33. - name: "epochs"
  34. value: "100"
  35. resources: # user defined resources
  36. limits:
  37. memory: 8Gi
  38. trainingWorkers:
  39. - dataset:
  40. name: "coco-dataset-1"
  41. template:
  42. spec:
  43. nodeName: $EDGE1_NODE
  44. containers:
  45. - image: kubeedge/sedna-example-federated-learning-mistnet-yolo-client:v0.4.0
  46. name: train-worker
  47. imagePullPolicy: IfNotPresent
  48. args: [ "-i", "1" ]
  49. env: # user defined environments
  50. - name: "cut_layer"
  51. value: "4"
  52. - name: "epsilon"
  53. value: "100"
  54. - name: "aggregation_algorithm"
  55. value: "mistnet"
  56. - name: "batch_size"
  57. value: "32"
  58. - name: "learning_rate"
  59. value: "0.001"
  60. - name: "epochs"
  61. value: "1"
  62. resources: # user defined resources
  63. limits:
  64. memory: 2Gi
  65. - dataset:
  66. name: "coco-dataset-2"
  67. template:
  68. spec:
  69. nodeName: $EDGE2_NODE
  70. containers:
  71. - image: kubeedge/sedna-example-federated-learning-mistnet-yolo-client:v0.4.0
  72. name: train-worker
  73. imagePullPolicy: IfNotPresent
  74. args: [ "-i", "2" ]
  75. env: # user defined environments
  76. - name: "cut_layer"
  77. value: "4"
  78. - name: "epsilon"
  79. value: "100"
  80. - name: "aggregation_algorithm"
  81. value: "mistnet"
  82. - name: "batch_size"
  83. value: "32"
  84. - name: "learning_rate"
  85. value: "0.001"
  86. - name: "epochs"
  87. value: "1"
  88. resources: # user defined resources
  89. limits:
  90. memory: 2Gi
  91. EOF

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号