Suite à l'article précédent, KubeEdge, EdgeMesh et Sedna sont déjà déployés. Ensuite, on lance l'exemple d'inférence conjointe d'après la doc officielle.
Doc officielle : https://sedna.readthedocs.io/en/latest/examples/joint_inference/helmet_detection_inference/README.html#
Tant que EdgeMesh a bien été déployé, cet exemple ne devrait pas poser de problème si on suit la doc.
Préparer les données et les modèles
- Télécharger le petit modèle sur le edge
mkdir -p /data/little-model
cd /data/little-model
wget <https://kubeedge.obs.cn-north-1.myhuaweicloud.com/examples/helmet-detection-inference/little-model.tar.gz>
tar -zxvf little-model.tar.gz- Télécharger le gros modèle sur le cloud
mkdir -p /data/big-model
cd /data/big-model
wget <https://kubeedge.obs.cn-north-1.myhuaweicloud.com/examples/helmet-detection-inference/big-model.tar.gz>
tar -zxvf big-model.tar.gz- Préparer les images
Worker d'inférence petit modèle : kubeedge/sedna-example-joint-inference-helmet-detection-little:v0.3.0
Worker d'inférence gros modèle : kubeedge/sedna-example-joint-inference-helmet-detection-big:v0.3.0
git clone <https://github.com/kubeedge/sedna.git>
./examples/build_image.sh joint_inference # 后面加joint_inference就只生成联合推理的镜像,不加的话就把包括联邦学习那些都生成了Si c'est trop lent, ce que j'ai fait, c'est ajouter ceci dans les fichiers de build d'image (joint-inference-helmet-detection-big.Dockerfile et joint-inference-helmet-detection-little.Dockerfile)
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get clean
RUN pip config set global.index-url <http://mirrors.aliyun.com/pypi/simple>
RUN pip config set install.trusted-host mirrors.aliyun.com
RUN pip install --upgrade pipAjouter des miroirs apt et pip.
Créer le service d'inférence conjointe
(toutes les ops kubectl se font côté cloud)
- Créer l'objet ressource du gros modèle sur le cloud
kubectl create -f - <<EOF
apiVersion: sedna.io/v1alpha1
kind: Model
metadata:
name: helmet-detection-inference-big-model
namespace: default
spec:
url: "/data/big-model/yolov3_darknet.pb"
format: "pb"
EOF- Créer l'objet ressource du petit modèle pour le edge
kubectl create -f - <<EOF
apiVersion: sedna.io/v1alpha1
kind: Model
metadata:
name: helmet-detection-inference-little-model
namespace: default
spec:
url: "/data/little-model/yolov3_resnet18.pb"
format: "pb"
EOFCôté edge, créer un dossier ; les images d'inférence y sont toutes générées :
mkdir -p /joint_inference/outputCôté cloud, définir les variables d'environnement CLOUD_NODE et EDGE_NODE
CLOUD_NODE="cloud-node-name"
EDGE_NODE="edge-node-name"Côté cloud, créer le service d'inférence conjointe. J'ai remplacé les images par des miroirs en Chine. Contenu du fichier :
kind: JointInferenceService
metadata:
name: helmet-detection-inference-example
namespace: default
spec:
edgeWorker:
model:
name: "helmet-detection-inference-little-model"
hardExampleMining:
name: "IBT"
parameters:
- key: "threshold_img"
value: "0.9"
- key: "threshold_box"
value: "0.9"
template:
spec:
nodeName: $EDGE_NODE
dnsPolicy: ClusterFirstWithHostNet
containers:
- image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/kubeedge/sedna-example-joint-inference-helmet-detection-little:v0.3.0
imagePullPolicy: IfNotPresent
name: little-model
env: # user defined environments
- name: input_shape
value: "416,736"
- name: "video_url"
value: "rtsp://localhost/video"
- name: "all_examples_inference_output"
value: "/data/output"
- name: "hard_example_cloud_inference_output"
value: "/data/hard_example_cloud_inference_output"
- name: "hard_example_edge_inference_output"
value: "/data/hard_example_edge_inference_output"
resources: # user defined resources
requests:
memory: 64M
cpu: 100m
limits:
memory: 2Gi
volumeMounts:
- name: outputdir
mountPath: /data/
volumes: # user defined volumes
- name: outputdir
hostPath:
# user must create the directory in host
path: /joint_inference/output
type: Directory
cloudWorker:
model:
name: "helmet-detection-inference-big-model"
template:
spec:
nodeName: $CLOUD_NODE
dnsPolicy: ClusterFirstWithHostNet
containers:
- image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/kubeedge/sedna-example-joint-inference-helmet-detection-big:v0.3.0
name: big-model
imagePullPolicy: IfNotPresent
env: # user defined environments
- name: "input_shape"
value: "544,544"
resources: # user defined resources
requests:
memory: 2Gi
EOFSimuler un flux vidéo sur le edge pour l'inférence
- 1.Installer le serveur de streaming open source EasyDarwin.
- 2.Démarrer le serveur EasyDarwin.
- 3.Télécharger la vidéo.
- 4.Pousser le flux vers une URL joignable par le service d'inférence (ex.
rtsp://localhost/video).
(L'adresse donnée dans la doc pour EasyDarwin-linux-8.1.0-1901141151.tar.gz ne doit plus marcher, mais je l'ai trouvée sur un site et téléchargée)
cd EasyDarwin-linux-8.1.0-1901141151
./start.sh
mkdir -p /data/video
cd /data/video
wget <https://kubeedge.obs.cn-north-1.myhuaweicloud.com/examples/helmet-detection-inference/video.tar.gz>
tar -zxvf video.tar.gz
ffmpeg -re -i /data/video/video.mp4 -vcodec libx264 -f rtsp rtsp://localhost/videoSi tout tourne normalement, les pods sont en running, et on peut voir les résultats d'inférence dans le chemin de sortie défini dans la config JointInferenceService (ex. /joint_inference/output).