Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
gireg.roussel committed Dec 26, 2024
1 parent 64d910c commit aaa294b
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 102 deletions.
2 changes: 1 addition & 1 deletion deployment/edge/ansible/files/docker-compose.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ services:
SERVING_MODEL_URL: http://edge_model_serving:8501
GOOGLE_APPLICATION_CREDENTIALS: /edge_orchestrator/config/secrets/credentials.json
GCP_BUCKET_NAME: tf-vio-bucket
ACTIVE_CONFIG_NAME: duck_detector_with_2_usbcamera
ACTIVE_CONFIG_NAME: marker_classification_with_1_fake_camera

edge_interface:
container_name: edge_interface
Expand Down
2 changes: 1 addition & 1 deletion deployment/edge/gcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

### Launch VIO
```shell
$ make edge_orchestrator
$ make vio-edge-up:
```

## Deploy edge on GCP via Kube
Expand Down
7 changes: 3 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ services:
- 8000:8000
environment:
EDGE_NAME: vio-edge-1
API_CONFIG: upload-gcp
API_CONFIG: docker
SERVING_MODEL_URL: http://edge_model_serving:8501
GOOGLE_APPLICATION_CREDENTIALS: /edge_orchestrator/config/secrets/credentials.json
GCP_BUCKET_NAME: tf-vio-bucket
ACTIVE_CONFIG_NAME: marker_classification_with_1_fake_camera
MONGO_DB_URI: mongodb://edge_db:27017/
POSTGRES_DB_URI: postgresql://vio:vio@hub_monitoring_db:5432/vio
profiles: [edge]

hub_labelizer:
Expand Down
2 changes: 1 addition & 1 deletion edge_orchestrator/.python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9
3.8
13 changes: 0 additions & 13 deletions edge_orchestrator/config/inventory.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,6 @@
320
],
"objectness_threshold": 0.3
},
"duck_detector": {
"category": "classification",
"version": 1,
"class_names": [
"OK",
"NOK",
"NOK2"
],
"image_resolution": [
224,
224
]
}
},
"camera_rules": [
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ class UploadWithGCPBucket(Config):
SERVING_MODEL_URL = os.environ.get("SERVING_MODEL_URL", "http://edge_model_serving:8501")

def __init__(self):
self.metadata_storage = GCPMetadataStorage()
self.binary_storage = GCPBinaryStorage()
prefix = os.getenv("EDGE_NAME")
if prefix is None:
raise Exception("EDGE_NAME environment variable should be set")

self.metadata_storage = GCPMetadataStorage(prefix)
self.binary_storage = GCPBinaryStorage(prefix)
self.inventory = JsonInventory(self.ROOT_PATH / "config" / "inventory.json")
self.station_config = JsonStationConfig(
self.ROOT_PATH / "config" / "station_configs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@


class GCPBinaryStorage(BinaryStorage):
def __init__(self):
def __init__(self, prefix: str):
self.storage_client = storage.Client()

prefix = os.getenv("EDGE_NAME")
if prefix is None:
raise Exception("EDGE_NAME environment variable should be set")
self.prefix = prefix
self.bucket = self.storage_client.get_bucket(os.getenv("GCP_BUCKET_NAME"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@


class GCPMetadataStorage(MetadataStorage):
def __init__(self):
def __init__(self, prefix: str):
self.storage_client = storage.Client()

prefix = os.getenv("EDGE_NAME")
if prefix is None:
raise Exception("EDGE_NAME environment variable should be set")
self.prefix = prefix
self.bucket = self.storage_client.get_bucket(os.getenv("GCP_BUCKET_NAME"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def perform_post_processing(self, model: ModelInfos, json_outputs: list, binary_
number_predictions_classes = len(predictions)
number_model_classes = len(model.class_names)
if number_predictions_classes != number_model_classes:
raise Exception(
logger.warning(
f"Number of classes in the model ({number_model_classes}) is different from"
"the number of predictions ({number_predictions_classes})"
)
Expand Down
1 change: 1 addition & 0 deletions edge_orchestrator/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
"host_volume_path_suffix": "edge_model_serving",
}
EDGE_TFLITE_SERVING_IMG = "ghcr.io/octo-technology/vio/edge_tflite_serving:main"
EDGE_NAME = "edge_test"
20 changes: 6 additions & 14 deletions edge_orchestrator/tests/fixtures/binaries.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import os

from _pytest.fixtures import fixture

from tests.conftest import TEST_DATA_FOLDER_PATH
from tests.conftest import EDGE_NAME, TEST_DATA_FOLDER_PATH


@fixture(scope="function")
def my_binaries_0():
edge_name = "edge_test"
os.environ["EDGE_NAME"] = edge_name
with (TEST_DATA_FOLDER_PATH / edge_name / "test_config" / "item_0" / "camera_id1.jpg").open("br") as f1, (
TEST_DATA_FOLDER_PATH / edge_name / "test_config" / "item_0" / "camera_id2.jpg"
with (TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_0" / "camera_id1.jpg").open("br") as f1, (
TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_0" / "camera_id2.jpg"
).open("br") as f2:
picture_1 = f1.read()
picture_2 = f2.read()
Expand All @@ -19,9 +15,7 @@ def my_binaries_0():

@fixture(scope="function")
def my_binaries_1():
edge_name = "edge_test"
os.environ["EDGE_NAME"] = edge_name
with (TEST_DATA_FOLDER_PATH / edge_name / "test_config" / "item_1" / "camera_id1.jpg").open("br") as f:
with (TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_1" / "camera_id1.jpg").open("br") as f:
picture = f.read()
return {
"camera_id1": picture,
Expand All @@ -33,10 +27,8 @@ def my_binaries_1():

@fixture(scope="function")
def my_binaries_2():
edge_name = "edge_test"
os.environ["EDGE_NAME"] = edge_name
with (TEST_DATA_FOLDER_PATH / edge_name / "test_config" / "item_2" / "camera_id1.jpg").open("br") as f1, (
TEST_DATA_FOLDER_PATH / edge_name / "test_config" / "item_2" / "camera_id2.jpg"
with (TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_2" / "camera_id1.jpg").open("br") as f1, (
TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_2" / "camera_id2.jpg"
).open("br") as f2:
picture_2 = f1.read()
picture_3 = f2.read()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import json
import os

from fastapi.testclient import TestClient

from edge_orchestrator.api_config import get_metadata_storage
from edge_orchestrator.application.server import server
from tests.conftest import TEST_DATA_FOLDER_PATH
from tests.conftest import EDGE_NAME, TEST_DATA_FOLDER_PATH


class TestServer:
def test_upload_route__should_return_expected_logs_when_received_paylod_with_binary_image(self, caplog):
# Given
edge_name = "edge_test"
os.environ["EDGE_NAME"] = edge_name

client = TestClient(server())
test_file = "camera_id1.jpg"
test_file_path = TEST_DATA_FOLDER_PATH / edge_name / "test_config" / "item_2" / test_file
test_file_path = TEST_DATA_FOLDER_PATH / EDGE_NAME / "test_config" / "item_2" / test_file
expected_logs = [
"Starting Save Binaries",
"Entering try Save Binaries",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from edge_orchestrator.infrastructure.binary_storage.gcp_binary_storage import (
GCPBinaryStorage,
)
from tests.conftest import TEST_DATA_FOLDER_PATH
from tests.conftest import EDGE_NAME, TEST_DATA_FOLDER_PATH


class TestGCPBinaryStorage:
Expand Down Expand Up @@ -38,11 +38,9 @@ def test_save_item_binaries_should_write_image_in_gcp(self, mock_storage):
@patch("edge_orchestrator.infrastructure.binary_storage.gcp_binary_storage.storage")
def test_get_item_binary_should_return_image(self, mock_storage):
# Given
edge_name = "edge_test"
os.environ["EDGE_NAME"] = edge_name
test_active_config_name = "test_config"
test_camera_id = "1"
test_file_path = TEST_DATA_FOLDER_PATH / edge_name / test_active_config_name / "item_2" / "camera_id1.jpg"
test_file_path = TEST_DATA_FOLDER_PATH / EDGE_NAME / test_active_config_name / "item_2" / "camera_id1.jpg"
item = Item.from_nothing()
with open(test_file_path, "rb") as f:
item.binaries = {test_camera_id: f}
Expand Down

0 comments on commit aaa294b

Please sign in to comment.