Skip to content

biotune-ai-lab/sam-api

Repository files navigation

Run and visualize SAM

1a. run service in a Docker container

create .env.docker file from template; update environment variable values if needed

cp .env.docker.example .env.docker

build the Docker image

docker build -t biotune-ai .

run the Docker container service

docker compose up

1b. set up and run the service locally

create .env file from template; update environment variable values if needed

cp .env.example .env

set up a dedicated virtual environment to run the service

# (install uv)
# curl -LsSf https://astral.sh/uv/install.sh | sh
# https://docs.astral.sh/uv/getting-started/installation/

uv python install 3.11

uv sync

activate the environment to run commands without the uv run prefix

source .venv/bin/activate

install pre-commit git hook scripts

pre-commit install

download default vit-h SAM model checkpoint

mkdir -p models
curl -OL https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth -o models/sam_vit_h_4b8939.pth

more options

start the service

# development
fastapi dev --host 127.0.0.1 --port 54004 service.py

# production
uvicorn service:app --host 127.0.0.1 --port 54004

2. run the service

segment image locally

# (activate project virtual environment)
source .venv/bin/activate

python segment.py -i <input image path> -o <output image path> -c <model checkpoint path> -m <model type>

send test request to the service

IMAGE_PATH="<image path>"
curl -X POST "http://localhost:8000/process" \
     -F "image=@$IMAGE_PATH" \
     -F "filename=$(basename $IMAGE_PATH)"

service documentation: http://127.0.0.1:54004/docs

NOTE: The service is designed to run locally and currently doesn't incorporate authentication or other security features.

About

segment images using sam

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •