Skip to content

Commit a191a73

Browse files
authored
Edge orchestrator/unify model fowarder (#127)
refactor: unify ModelForwarders to make tflite_serving responsible of prediction types
1 parent 274b563 commit a191a73

41 files changed

Lines changed: 265 additions & 712 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci_edge_model_serving.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ on:
88
- main
99
pull_request:
1010
paths:
11-
- 'edge_model_serving/**'
11+
- "edge_model_serving/**"
1212

1313
jobs:
1414
lint_and_test_on_edge_model_serving:
1515
name: Run Python linter and tests (unit > integration > functional)
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
python-version: [ "3.10", "3.11" ]
19+
python-version: ["3.10", "3.11"]
2020
steps:
2121
- name: Checkout repository
2222
uses: actions/checkout@v4
@@ -31,7 +31,7 @@ jobs:
3131
working-directory: ./edge_model_serving/tflite_serving
3232

3333
- name: Lint with flake8 and black
34-
run: make lint
34+
run: make check
3535
working-directory: ./edge_model_serving/tflite_serving
3636

3737
- name: Run unit tests

.github/workflows/ci_edge_orchestrator.yml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,24 @@ on:
88
- main
99
pull_request:
1010
paths:
11-
- 'edge_orchestrator/**'
11+
- "edge_orchestrator/**"
1212

1313
jobs:
1414
lint_and_test_on_edge_orchestrator:
1515
name: Run Python linter and tests (unit > integration > functional)
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
python-version: [ "3.9", "3.10", "3.11" ]
19+
python-version: ["3.9", "3.10", "3.11"]
2020
services:
21-
edge_model_serving:
22-
image: ghcr.io/octo-technology/vio/edge_model_serving:main
23-
ports:
24-
- 8501:8501
2521
edge_tflite_serving:
2622
image: ghcr.io/octo-technology/vio/edge_tflite_serving:main
2723
ports:
28-
- 8502:8501
24+
- 8501:8501
25+
options: --platform linux/amd64
2926
env:
30-
TENSORFLOW_SERVING_HOST: localhost
31-
TENSORFLOW_SERVING_PORT: 8501
3227
TFLITE_SERVING_HOST: localhost
33-
TFLITE_SERVING_PORT: 8502
28+
TFLITE_SERVING_PORT: 8501
3429
steps:
3530
- name: Checkout repository
3631
uses: actions/checkout@v4
@@ -45,7 +40,7 @@ jobs:
4540
working-directory: ./edge_orchestrator
4641

4742
- name: Lint with flake8 and black
48-
run: make lint
43+
run: make check
4944
working-directory: ./edge_orchestrator
5045
- name: Run unit tests
5146
run: make unit_tests
@@ -59,6 +54,23 @@ jobs:
5954
path: edge_orchestrator/reports/pytest/unit-tests-report.xml
6055
reporter: java-junit
6156

57+
- name: Wait for edge_tflite_serving to be ready
58+
run: |
59+
for i in {1..30}; do
60+
if curl -sf --max-time 2 http://localhost:8501/v1/; then
61+
echo "Service is up!"
62+
exit 0
63+
fi
64+
echo "Waiting... ($i/30)"
65+
sleep 2
66+
done
67+
echo "=== Container status ==="
68+
docker ps -a
69+
echo "=== edge_tflite_serving logs ==="
70+
docker logs $(docker ps -aq --filter "ancestor=ghcr.io/octo-technology/vio/edge_tflite_serving:main") 2>&1 || echo "Could not get container logs"
71+
echo "Service did not start in time" >&2
72+
exit 1
73+
6274
- name: Run integration tests
6375
run: make integration_tests
6476
working-directory: ./edge_orchestrator
@@ -100,4 +112,3 @@ jobs:
100112
secrets:
101113
username: ${{ github.actor }}
102114
password: ${{ secrets.GITHUB_TOKEN }}
103-

edge_model_serving/tflite_serving/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ RUN apt-get update && apt-get upgrade -y && \
1010
apt-get install -y --no-install-recommends \
1111
build-essential \
1212
gcc \
13+
patchelf \
1314
&& apt clean \
1415
&& apt autoremove \
1516
&& rm -rf /var/cache/apt/archives/* \
@@ -27,7 +28,8 @@ COPY tflite_serving/src/ ./src
2728
COPY tflite_serving/pip.conf /opt/venv/pip.conf
2829
COPY models/tflite/ $MODELS_PATH/tflite/
2930

30-
RUN pip install --no-cache-dir .
31+
RUN pip install --no-cache-dir . && \
32+
find /opt/venv -name "*.so" -exec patchelf --clear-execstack {} \; 2>/dev/null || true
3133

3234
EXPOSE 8501
3335
ENTRYPOINT ["uvicorn", "tflite_serving.tflite_server:app"]

edge_model_serving/tflite_serving/src/tflite_serving/api_routes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import io
2-
import io
32
import logging
43
from typing import Any, Dict, List, Optional, cast
54

@@ -233,6 +232,5 @@ async def predict(
233232
except HTTPException:
234233
raise
235234
except Exception as e:
236-
logging.exception(f"Prediction error for model '{model_name}'")
237235
logging.exception(f"Prediction error for model '{model_name}'")
238236
raise HTTPException(status_code=500, detail=str(e))

edge_orchestrator/Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
ARG PYTHON_VERSION="3.11"
22

3-
FROM --platform=$TARGETPLATFORM python:${PYTHON_VERSION}-slim
3+
FROM --platform=$TARGETPLATFORM python:${PYTHON_VERSION}-slim-bookworm
44
ARG TARGETPLATFORM
55
ARG BUILDOS
66

77
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] && [ "$BUILDOS" = "linux" ]; then \
8-
apt update && apt install -y --no-install-recommends gnupg; \
9-
echo "deb http://archive.raspberrypi.org/debian/ bookworm main" > /etc/apt/sources.list.d/raspi.list \
10-
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 82B129927FA3303E; \
8+
echo "deb [trusted=yes] http://archive.raspberrypi.org/debian/ bookworm main" \
9+
> /etc/apt/sources.list.d/raspi.list; \
1110
fi
1211

1312
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] && [ "$BUILDOS" = "linux" ]; then \

edge_orchestrator/config/marker_classif_with_1_raspberry_cam.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,8 @@
77
"position": "front",
88
"model_forwarder_config": {
99
"model_name": "marker_quality_control",
10-
"model_type": "classification",
1110
"model_serving_url": "http://edge_model_serving:8501/",
12-
"expected_image_resolution": {
13-
"width": 224,
14-
"height": 224
15-
},
16-
"model_version": "1",
17-
"class_names": [
18-
"OK",
19-
"KO"
20-
]
11+
"model_version": "1"
2112
},
2213
"camera_rule_config": {
2314
"camera_rule_type": "expected_label_rule",
@@ -38,4 +29,4 @@
3829
"expected_decision": "OK",
3930
"threshold": 1
4031
}
41-
}
32+
}

edge_orchestrator/config/marker_classif_with_1_usb_cam.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,8 @@
88
"position": "front",
99
"model_forwarder_config": {
1010
"model_name": "marker_quality_control",
11-
"model_type": "classification",
1211
"model_serving_url": "http://edge_model_serving:8501/",
13-
"expected_image_resolution": {
14-
"width": 224,
15-
"height": 224
16-
},
17-
"model_version": "1",
18-
"class_names": [
19-
"OK",
20-
"KO"
21-
]
12+
"model_version": "1"
2213
},
2314
"camera_rule_config": {
2415
"camera_rule_type": "expected_label_rule",
@@ -39,4 +30,4 @@
3930
"expected_decision": "OK",
4031
"threshold": 1
4132
}
42-
}
33+
}

edge_orchestrator/config/marker_classif_with_2_fake_cam.json

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,8 @@
88
"position": "front",
99
"model_forwarder_config": {
1010
"model_name": "marker_quality_control",
11-
"model_type": "classification",
1211
"model_serving_url": "http://edge_model_serving:8501/",
13-
"expected_image_resolution": {
14-
"width": 224,
15-
"height": 224
16-
},
17-
"model_version": "1",
18-
"class_names": [
19-
"OK",
20-
"KO"
21-
]
12+
"model_version": "1"
2213
},
2314
"camera_rule_config": {
2415
"camera_rule_type": "expected_label_rule",
@@ -32,17 +23,8 @@
3223
"position": "back",
3324
"model_forwarder_config": {
3425
"model_name": "marker_quality_control",
35-
"model_type": "classification",
3626
"model_serving_url": "http://edge_model_serving:8501/",
37-
"expected_image_resolution": {
38-
"width": 224,
39-
"height": 224
40-
},
41-
"model_version": "1",
42-
"class_names": [
43-
"OK",
44-
"KO"
45-
]
27+
"model_version": "1"
4628
},
4729
"camera_rule_config": {
4830
"camera_rule_type": "expected_label_rule",
@@ -63,4 +45,4 @@
6345
"expected_decision": "OK",
6446
"threshold": 1
6547
}
66-
}
48+
}

edge_orchestrator/config/mobilenet_ssd_v2_coco_with_2_usb_cam.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@
88
"position": "front",
99
"model_forwarder_config": {
1010
"model_name": "yolo_coco_nano",
11-
"model_type": "object_detection",
1211
"model_serving_url": "http://edge_model_serving:8501/",
13-
"expected_image_resolution": {
14-
"width": 320,
15-
"height": 320
16-
},
17-
"model_version": "1",
18-
"class_names_filepath": "model_labels/coco_labels.txt"
12+
"model_version": "1"
1913
},
2014
"camera_rule_config": {
2115
"camera_rule_type": "min_nb_objects_rule",
@@ -30,14 +24,8 @@
3024
"position": "back",
3125
"model_forwarder_config": {
3226
"model_name": "yolo_coco_nano",
33-
"model_type": "object_detection",
3427
"model_serving_url": "http://edge_model_serving:8501/",
35-
"expected_image_resolution": {
36-
"width": 320,
37-
"height": 320
38-
},
39-
"model_version": "1",
40-
"class_names_filepath": "model_labels/coco_labels.txt"
28+
"model_version": "1"
4129
},
4230
"camera_rule_config": {
4331
"camera_rule_type": "min_nb_objects_rule",
@@ -59,4 +47,4 @@
5947
"expected_decision": "OK",
6048
"threshold": 1
6149
}
62-
}
50+
}

edge_orchestrator/config/pin_detection_with_1_usb_cam.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,8 @@
88
"position": "front",
99
"model_forwarder_config": {
1010
"model_name": "pin_detection",
11-
"model_type": "classification",
1211
"model_serving_url": "http://edge_model_serving:8501/",
13-
"expected_image_resolution": {
14-
"width": 224,
15-
"height": 224
16-
},
17-
"model_version": "1",
18-
"class_names": [
19-
"OK",
20-
"KO"
21-
]
12+
"model_version": "1"
2213
},
2314
"camera_rule_config": {
2415
"camera_rule_type": "expected_label_rule",
@@ -39,4 +30,4 @@
3930
"expected_decision": "OK",
4031
"threshold": 1
4132
}
42-
}
33+
}

0 commit comments

Comments
 (0)