Skip to content
Snippets Groups Projects
Commit 6a682001 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Segmentation pipeline over API raises correct HTTPException

parent edf40efa
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ from ..accessors import GenericImageDataAccessor, generate_file_accessor, write_
from ..models import SemanticSegmentationModel
from ..process import smooth
from ..util import PipelineTrace
from ..session import session
from ..session import session, AccessorIdError
from pydantic import BaseModel, Field, validator
......@@ -26,7 +26,11 @@ class SegmentParams(BaseModel):
@validator('accessor_id')
def accessor_is_loaded(cls, v):
if not session.get_accessor_info(v)['loaded']:
try:
acc_info = session.get_accessor_info(v)
except AccessorIdError as e:
raise HTTPException(status_code=409, detail=str(e))
if not acc_info['loaded']:
raise HTTPException(status_code=409, detail=f'Accessor with ID {v} is not loaded')
return v
......@@ -43,14 +47,16 @@ def segment(p: SegmentParams) -> SegmentRecord:
"""
Run a semantic segmentation model to compute a binary mask from an input image
"""
acc_in = session.get_accessor(p.accessor_id, pop=True)
steps = pipeline(
acc_in,
session.models[p.model_id]['object'],
**p.dict(),
)
session.log_info(f'Completed segmentation of {p.accessor_id}')
return SegmentRecord(
output_accessor_id=session.add_accessor(steps.last),
model_id=p.model_id,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment