Skip to content

Commit

Permalink
use ray object store
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsmechtel committed Jan 30, 2025
1 parent 0052c8d commit 86f5761
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 19 additions & 16 deletions bioimageio_colab/register_sam_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,29 +153,32 @@ async def compute_image_embedding(
"""
Compute the embeddings of an image using the specified model.
"""
async with semaphore:
try:
user = context["user"]
if require_login and user["is_anonymous"]:
raise PermissionError("You must be logged in to use this service.")

user_id = user["id"]
try:
user = context["user"]
if require_login and user["is_anonymous"]:
raise PermissionError("You must be logged in to use this service.")
user_id = user["id"]

# Put image immediately into the object store to avoid memory issues
logger.info(f"User '{user_id}' - Putting image into the object store...")
obj_ref = ray.put(image)
del image

# Compute the embedding, but limit the number of concurrent requests
async with semaphore:
logger.info(
f"User '{user_id}' - Computing embedding (model: '{model_id}')..."
)

# Compute the embedding
# Returns: {"features": embedding, "input_size": input_size}

# Format: {"features": embedding, "input_size": input_size}
result = await app_handle.options(multiplexed_model_id=model_id).remote(
image
obj_ref
)

logger.info(f"User '{user_id}' - Embedding computed successfully.")

return result
except Exception as e:
logger.error(f"User '{user_id}' - Error computing embedding: {e}")
raise e
except Exception as e:
logger.error(f"User '{user_id}' - Error computing embedding: {e}")
raise e


# def compute_mask(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools", "wheel"]

[project]
name = "bioimageio-colab"
version = "0.2.6"
version = "0.2.7"
readme = "README.md"
description = "Collaborative image annotation and model training with human in the loop."
dependencies = [
Expand Down

0 comments on commit 86f5761

Please sign in to comment.