From 619a23f850426ce0ae9c980cc0036c4d7eb017d4 Mon Sep 17 00:00:00 2001 From: ChromaticPanic <78883122+ChromaticPanic@users.noreply.github.com> Date: Tue, 19 Nov 2024 03:15:42 +0000 Subject: [PATCH] Fix seed detector processing --- .devcontainer/devcontainer.json | 4 +++- .gitignore | 7 +++++++ app.py | 2 +- model/__init__.py | 2 ++ model/seed_detector.py | 5 +++-- model/swin.py | 3 ++- requirements.txt | 12 +++++++----- 7 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index dafa512..6d1152e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,6 +7,8 @@ "features": { "ghcr.io/devcontainers/features/azure-cli:1": {} }, + // uncomment the next line for LAN model access + // "runArgs": ["--network=host"], // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, @@ -15,7 +17,7 @@ // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "pip3 install --user -r requirements.txt && pip install --upgrade pydantic", + "postCreateCommand": "pip3 install --user -r requirements.txt", // && pip install --upgrade pydantic", // Configure tool-specific properties. "customizations": { diff --git a/.gitignore b/.gitignore index c2ac1b3..a843240 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,10 @@ *.pyc .vscode/settings.json output.* + +bin/ +lib64/ +lib64 +**/*pyvenv.cfg +share/ +lib/ \ No newline at end of file diff --git a/app.py b/app.py index 932439e..c09b524 100644 --- a/app.py +++ b/app.py @@ -133,7 +133,7 @@ class MaxContentLengthWarning(APIWarnings): CACHE = {"seeds": None, "endpoints": None, "pipelines": {}, "validators": []} cors_settings = { - "allow_origin": [URL_LOCAL] if ENVIRONMENT == "local" else [URL_PROD], + "allow_origin": [URL_PROD, URL_LOCAL], "allow_methods": ["GET", "POST", "OPTIONS"], "allow_credentials": True, "max_age": 86400 diff --git a/model/__init__.py b/model/__init__.py index 6debf77..211759a 100644 --- a/model/__init__.py +++ b/model/__init__.py @@ -6,6 +6,8 @@ request_function = { "swinv1-base-dataaugv2-1": request_inference_from_swin, "seed-detector-1": request_inference_from_seed_detector, + "swinv1-base-dataaugv2-2": request_inference_from_swin, + "seed-detector-rcnn-1": request_inference_from_seed_detector, "test": request_inference_from_test, "m-14of15seeds-6seedsmag": request_inference_from_nachet_6seeds } diff --git a/model/seed_detector.py b/model/seed_detector.py index a0504b0..b008f90 100644 --- a/model/seed_detector.py +++ b/model/seed_detector.py @@ -92,11 +92,12 @@ async def request_inference_from_seed_detector(model: namedtuple, previous_resul } body = str.encode(json.dumps(data)) - req = Request(model.endpoint, body, headers) + req = Request(model.endpoint, body, headers, method="POST") + # req = Request("http://192.168.x.x:12380/score", body, headers, method="POST") response = urlopen(req) result = response.read() - result_object = json.loads(result.decode("utf8")) + result_object = [json.loads(result.decode("utf8"))] print(json.dumps(result_object[0].get("boxes"), indent=4)) #TODO Transform into logging return { diff --git a/model/swin.py b/model/swin.py index 8058e58..8164d1a 100644 --- a/model/swin.py +++ b/model/swin.py @@ -56,7 +56,8 @@ async def request_inference_from_swin(model: namedtuple, previous_result: 'list[ model.deployment_platform: model.name } body = img - req = Request(model.endpoint, body, headers) + req = Request(model.endpoint, body, headers, method="POST") + # req = Request("http://192.168.x.x:12390/score", body, headers, method="POST") response = urlopen(req) result = response.read() results.append(json.loads(result.decode("utf8"))) diff --git a/requirements.txt b/requirements.txt index 488f660..82b218d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,16 @@ -numpy +nachet-datastore @git+https://github.com/ai-cfia/ailab-datastore.git@v1.0.0-nachet-datastore +numpy==1.26.4 azure-storage-blob azure-identity -quart +flask==3.0.3 +quart==0.19.6 quart-cors python-dotenv hypercorn -Pillow +Pillow==10.3.0 cryptography pyyaml -pydantic +pydantic==2.7.1 +pydantic-core==2.18.2 python-magic PyJWT -nachet-datastore @git+https://github.com/ai-cfia/ailab-datastore.git@v1.0.0-nachet-datastore