You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 8.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. # Using Lifelong Learning in Campus Robot Delivery Scenario
  2. ## Introduction
  3. This example introduces how to use Sedna lifelong learning to implement the lifelong learning delivery task of the robot in a campus. Based on open source project [RFNet](https://github.com/AHupuJR/RFNet) as base model, we realize intelligent perception of environment with Sedna lifelong learning in this example.
  4. The demo mainly shows:
  5. 1. Lifelong learning unseen task recognition algorithm (prediction) can identify and collect unseen task samples.
  6. 2. Lifelong learning unseen task recognition algorithm (detection) can trigger alarms to remind robot admin that emergency response is required.
  7. 3. Lifelong learning unseen task training algorithm improves the inference accuracy of known categories and the ability to identify new categories.
  8. ### Install Sedna
  9. Follow the [Sedna installation document](/docs/setup/install.md) to install Sedna.
  10. ### Configurations
  11. #### Prepare Images
  12. This example uses the following images:
  13. - Training worker: kubeedge/sedna-example-lifelong-learning-cityscapes-segmentation:v0.6.0
  14. - Evaluation worker: kubeedge/sedna-example-lifelong-learning-cityscapes-segmentation:v0.6.0
  15. - Inference worker: kubeedge/sedna-example-lifelong-learning-cityscapes-segmentation:v0.6.0
  16. These images are generated by the script [build_images.sh](/examples/build_image.sh).
  17. Users can also generate customized images for different workers and config them in yaml which will be presented in the following steps.
  18. #### Prepare user nodes
  19. ```
  20. WORKER_NODE=sedna-mini-control-plane
  21. DATA_NODE=$WORKER_NODE
  22. TRAIN_NODE=$WORKER_NODE
  23. EVAL_NODE=$WORKER_NODE
  24. INFER_NODE=$WORKER_NODE
  25. ```
  26. Particularly, data node, train node, eval node and infer node are custom codes which can be specified by users for actual running. Here, for simplicity, we use the same node to demonstrate.
  27. #### Prepare Dataset
  28. Step 1: Users can use semantic segmentation datasets from [CITYSCAPES](https://www.cityscapes-dataset.com/). While we also provide a re-organized [dataset segmentation_data.zip](https://kubeedge.obs.cn-north-1.myhuaweicloud.com/examples/robo_dog_delivery/segmentation_data.zip) of CITYSCAPES as an example for training and evaluation.
  29. Download and unzip segmentation_data.zip. Put it into /data of ```$DATA_NODE```. Or you can use ```docker exec``` to get into ```$DATA_NODE``` and then execute the following commands.
  30. ```
  31. mkdir /data
  32. cd /data
  33. wget https://kubeedge.obs.cn-north-1.myhuaweicloud.com/examples/robo_dog_delivery/segmentation_data.zip
  34. unzip segmentation_data.zip
  35. ```
  36. Step 2: download [test data](https://kubeedge.obs.cn-north-1.myhuaweicloud.com/examples/robo_dog_delivery/test_data.zip) which is for demonstration at the inference stage, unzip test_data.zip and put it into /data of ```$INFER_NODE```. Or you can use ```docker exec``` to get into ```$INFER_NODE``` and then execute the following commands.
  37. ```
  38. mkdir /data
  39. cd /data
  40. wget https://kubeedge.obs.cn-north-1.myhuaweicloud.com/examples/robo_dog_delivery/test_data.zip
  41. unzip test_data.zip
  42. ```
  43. After finishing the above preparations, execute the following commands to config.
  44. ```
  45. local_prefix=/data
  46. cloud_image=kubeedge/sedna-example-lifelong-learning-cityscapes-segmentation:v0.6.0
  47. edge_image=kubeedge/sedna-example-lifelong-learning-cityscapes-segmentation:v0.6.0
  48. data_url=$local_prefix/segmentation_data/data.txt
  49. OUTPUT=$local_prefix/lifelonglearningjob/output
  50. job_name=robo-demo
  51. ```
  52. ### Create Lifelong Learning Job
  53. #### Create Initial Dataset Resource
  54. ```
  55. kubectl create -f - <<EOF
  56. apiVersion: sedna.io/v1alpha1
  57. kind: Dataset
  58. metadata:
  59. name: lifelong-robo-dataset
  60. spec:
  61. url: "$data_url"
  62. format: "txt"
  63. nodeName: "$DATA_NODE"
  64. EOF
  65. ```
  66. #### Create Robot Dog Delivery Lifelong Learning Job
  67. ```
  68. kubectl create -f - <<EOF
  69. apiVersion: sedna.io/v1alpha1
  70. kind: LifelongLearningJob
  71. metadata:
  72. name: $job_name
  73. spec:
  74. dataset:
  75. name: "lifelong-robo-dataset"
  76. trainProb: 0.8
  77. trainSpec:
  78. template:
  79. spec:
  80. nodeName: $TRAIN_NODE
  81. dnsPolicy: ClusterFirstWithHostNet
  82. containers:
  83. - image: $cloud_image
  84. name: train-worker
  85. imagePullPolicy: IfNotPresent
  86. args: ["train.py"]
  87. env:
  88. - name: "num_class"
  89. value: "24"
  90. - name: "epoches"
  91. value: "1"
  92. - name: "attribute"
  93. value: "real, sim"
  94. - name: "city"
  95. value: "bremen"
  96. - name: "BACKEND_TYPE"
  97. value: "PYTORCH"
  98. resources:
  99. limits:
  100. cpu: 6
  101. memory: 12Gi
  102. requests:
  103. cpu: 4
  104. memory: 12Gi
  105. volumeMounts:
  106. - mountPath: /dev/shm
  107. name: cache-volume
  108. volumes:
  109. - emptyDir:
  110. medium: Memory
  111. sizeLimit: 256Mi
  112. name: cache-volume
  113. trigger:
  114. checkPeriodSeconds: 30
  115. timer:
  116. start: 00:00
  117. end: 24:00
  118. condition:
  119. operator: ">"
  120. threshold: 100
  121. metric: num_of_samples
  122. evalSpec:
  123. template:
  124. spec:
  125. nodeName: $EVAL_NODE
  126. dnsPolicy: ClusterFirstWithHostNet
  127. containers:
  128. - image: $cloud_image
  129. name: eval-worker
  130. imagePullPolicy: IfNotPresent
  131. args: ["evaluate.py"]
  132. env:
  133. - name: "operator"
  134. value: "<"
  135. - name: "model_threshold"
  136. value: "0"
  137. - name: "num_class"
  138. value: "24"
  139. - name: "BACKEND_TYPE"
  140. value: "PYTORCH"
  141. resources:
  142. limits:
  143. cpu: 6
  144. memory: 12Gi
  145. requests:
  146. cpu: 4
  147. memory: 12Gi
  148. deploySpec:
  149. template:
  150. spec:
  151. nodeName: $INFER_NODE
  152. dnsPolicy: ClusterFirstWithHostNet
  153. hostNetwork: true
  154. containers:
  155. - image: $edge_image
  156. name: infer-worker
  157. imagePullPolicy: IfNotPresent
  158. args: ["predict.py"]
  159. env:
  160. - name: "test_data"
  161. value: "/data/test_data"
  162. - name: "num_class"
  163. value: "24"
  164. - name: "unseen_save_url"
  165. value: "/data/unseen_samples"
  166. - name: "INFERENCE_RESULT_DIR"
  167. value: "/data/infer_results"
  168. - name: "BACKEND_TYPE"
  169. value: "PYTORCH"
  170. volumeMounts:
  171. - name: unseenurl
  172. mountPath: /data/unseen_samples
  173. - name: inferdata
  174. mountPath: /data/infer_results
  175. - name: testdata
  176. mountPath: /data/test_data
  177. resources:
  178. limits:
  179. cpu: 6
  180. memory: 12Gi
  181. requests:
  182. cpu: 4
  183. memory: 12Gi
  184. volumes:
  185. - name: unseenurl
  186. hostPath:
  187. path: /data/unseen_samples
  188. type: DirectoryOrCreate
  189. - name: inferdata
  190. hostPath:
  191. path: /data/infer_results
  192. type: DirectoryOrCreate
  193. - name: testdata
  194. hostPath:
  195. path: /data/test_data
  196. type: DirectoryOrCreate
  197. outputDir: $OUTPUT/$job_name
  198. EOF
  199. ```
  200. ### Check Lifelong Learning Status
  201. ```
  202. kubectl get lifelonglearningjob
  203. ```
  204. ### Effect Display
  205. #### Evaluation results of two round lifelong learning
  206. <table class="tg">
  207. <thead>
  208. <tr>
  209. <th class="tg-lboi" rowspan="2">Rounds</th>
  210. <th class="tg-c3ow" colspan="3">Metrics</th>
  211. </tr>
  212. <tr>
  213. <th class="tg-0pky">Pixel Accuracy Class (CPA)</th>
  214. <th class="tg-0pky">Mean Intersection over Union (mIoU)</th>
  215. <th class="tg-0pky">Frequency Weighted Intersection over Union (FWIoU)</th>
  216. </tr>
  217. </thead>
  218. <tbody>
  219. <tr>
  220. <td class="tg-0pky">Round 1</td>
  221. <td class="tg-0pky">0.385</td>
  222. <td class="tg-0pky">0.319</td>
  223. <td class="tg-0pky">0.648</td>
  224. </tr>
  225. <tr>
  226. <td class="tg-0pky">Round 2</td>
  227. <td class="tg-0pky">0.402</td>
  228. <td class="tg-0pky">0.339</td>
  229. <td class="tg-0pky">0.659</td>
  230. </tr>
  231. </tbody>
  232. </table>
  233. #### Segmentation inference display
  234. ![Inference sample](./RFNet/images/2086.png) | ![Segementation display](./RFNet/images/2086_color.png)|![Merge](./RFNet/images/2086_merge.png)
  235. ---|---|---