From a4ae0ad33efdf280bc3e64318a48c1932ebcc0a7 Mon Sep 17 00:00:00 2001
From: Christopher Rhodes <christopher.rhodes@embl.de>
Date: Mon, 30 Oct 2023 17:36:11 +0100
Subject: [PATCH] Roughed in API for patch-based object classification workflow

---
 extensions/chaeo/router.py | 42 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 extensions/chaeo/router.py

diff --git a/extensions/chaeo/router.py b/extensions/chaeo/router.py
new file mode 100644
index 00000000..208aa7b9
--- /dev/null
+++ b/extensions/chaeo/router.py
@@ -0,0 +1,42 @@
+from fastapi import APIRouter, HTTPException
+
+from extensions.chaeo.workflows import infer_object_map_from_zstack
+from model_server.session import Session
+from model_server.validators import validate_workflow_inputs
+
+router = APIRouter(
+    prefix='/chaeo',
+    tags=['chaeo'],
+)
+
+session = Session()
+
+@router.put('/classify_zstack/infer')
+def infer_px_then_ob_maps(
+        px_model_id: str,
+        ob_model_id: str,
+        input_filename: str,
+        pxmap_threshold: float,
+        pxmap_foreground_channel: int,
+        segmentation_channel: int,
+        patches_channel: int,
+        zmask_filters: dict = {'area': (1e3, 1e8)},
+) -> dict:
+    inpath = session.paths['inbound_images'] / input_filename
+    validate_workflow_inputs([px_model_id, ob_model_id], [inpath])
+
+    record = infer_object_map_from_zstack(
+        inpath,
+        session.paths['outbound_images'],
+        [
+            session.models[px_model_id]['object'],
+            session.models[px_model_id]['object']
+        ],
+        pxmap_threshold=pxmap_threshold,
+        pxmap_foreground_channel=pxmap_foreground_channel,
+        segmentation_channel=segmentation_channel,
+        patches_channel=patches_channel,
+        zmask_filters=zmask_filters,
+    )
+
+    return record
\ No newline at end of file
-- 
GitLab