Skip to content

Commit

Permalink
Local serving and meta.output update (#9)
Browse files Browse the repository at this point in the history
* Local serving WIP

* Refactor configuration and commands for RT-DETRv2 service

* Update Dockerfile and configuration for RT-DETRv2: bump supervisely version to 6.73.307, update Docker image to 1.0.9, and increment instance version to 6.12.29

* Update Docker image version for RT-DETRv2 to 1.0.9 in docker-compose and configuration files
  • Loading branch information
cxnt authored Feb 14, 2025
1 parent 7f15766 commit 65ed522
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 53 deletions.
10 changes: 4 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"LOG_LEVEL": "DEBUG",
"DEBUG_APP_DIR": "app_data",
"APP_NAME": "Train RT-DETRv2",
"TEAM_ID": "33",
"WORKSPACE_ID": "90",
"PROJECT_ID": "553",
"TEAM_ID": "4",
"WORKSPACE_ID": "3",
"PROJECT_ID": "30",
}
},
{
Expand Down Expand Up @@ -69,9 +69,7 @@
"env": {
"PYTHONPATH": "${workspaceFolder}:${PYTHONPATH}",
"LOG_LEVEL": "DEBUG",
"DEBUG_APP_DIR": "app_data",
"DEBUG_WITH_SLY_NET": "1",
"APP_NAME": "Serve RT-DETRv2",
"TEAM_ID": "4",
}
},
{
Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
rtdetrv2:
image: supervisely/rt-detrv2:1.0.9
shm_size: 1g
runtime: nvidia
env_file:
- ~/supervisely.env
environment:
- PYTHONPATH=/app
volumes:
- .:/app
working_dir: /app
ports:
- "8000:8000"
expose:
- "8000"
entrypoint: [ "python3", "supervisely_integration/serve/main.py" ]
command: [ "--model", "RT-DETRv2-S" ]
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ RUN mkdir -p ~/.cache/supervisely/checkpoints && \
curl -L -o ~/.cache/supervisely/checkpoints/rtdetrv2_r50vd_6x_coco_ema.pth https://github.com/lyuwenyu/storage/releases/download/v0.1/rtdetrv2_r50vd_6x_coco_ema.pth && \
curl -L -o ~/.cache/supervisely/checkpoints/rtdetrv2_r101vd_6x_coco_from_paddle.pth https://github.com/lyuwenyu/storage/releases/download/v0.1/rtdetrv2_r101vd_6x_coco_from_paddle.pth

RUN pip install --no-cache-dir supervisely[training]==6.73.299
RUN pip install --no-cache-dir supervisely[training]==6.73.307
4 changes: 2 additions & 2 deletions docker/publish.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
docker build -t supervisely/rt-detrv2:1.0.8 . && \
docker push supervisely/rt-detrv2:1.0.8
docker build -t supervisely/rt-detrv2:1.0.9 . && \
docker push supervisely/rt-detrv2:1.0.9
8 changes: 4 additions & 4 deletions local.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# PROJECT_ID=42201 # 41710 # 42201

# DEMO
TASK_ID=2784
TEAM_ID=33
WORKSPACE_ID=90
PROJECT_ID=825
# TASK_ID=2784
# TEAM_ID=33
# WORKSPACE_ID=90
# PROJECT_ID=825
14 changes: 0 additions & 14 deletions supervisely_integration/gpu-cloud/Dockerfile

This file was deleted.

3 changes: 0 additions & 3 deletions supervisely_integration/gpu-cloud/publish.sh

This file was deleted.

4 changes: 2 additions & 2 deletions supervisely_integration/serve/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"gpu": "preferred",
"session_tags": ["deployed_nn"],
"community_agent": false,
"docker_image": "supervisely/rt-detrv2:1.0.8",
"docker_image": "supervisely/rt-detrv2:1.0.9",
"task_location": "application_sessions",
"license": {
"type": "Apache-2.0"
},
"instance_version": "6.12.28"
"instance_version": "6.12.29"
}
20 changes: 1 addition & 19 deletions supervisely_integration/serve/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,10 @@
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

model = RTDETRv2(
use_gui=True,
use_serving_gui_template=True,
)
model.serve()

# Local development
# PYTHONPATH="${PWD}:${PYTHONPATH}" \
# python ./supervisely_integration/serve/main.py \
# --model ./my_experiments/2315_RT-DETRv2/checkpoints/best.pth

# Docker deployment
# docker run \
# --shm-size=1g \
# --runtime=nvidia \
# --cap-add NET_ADMIN \
# --env-file ~/supervisely.env \
# --env ENV=production \
# --env LOCAL_DEPLOY=True \
# -v ".:/app" \
# -w /app \
# -p 8000:8000 \
# supervisely/rt-detrv2-gpu-cloud:1.0.3 \
# --model "RT-DETRv2-S"
65 changes: 65 additions & 0 deletions supervisely_integration/serve/scripts/serve_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os

from dotenv import load_dotenv

import supervisely as sly
from supervisely_integration.serve.rtdetrv2 import RTDETRv2

if sly.is_development():
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

################################
# 1. Serve with docker-compose #
################################
# Run the following command in the terminal:
# docker-compose up


################################
# 2. Run with docker run #
################################
# Run the following command in the terminal:
# docker run \
# --shm-size=1g \
# --runtime=nvidia \
# --env-file ~/supervisely.env \
# --env PYTHONPATH=/app \
# -v ".:/app" \
# -w /app \
# -p 8000:8000 \
# supervisely/rt-detrv2:1.0.9 \
# python3 supervisely_integration/serve/main.py --model "RT-DETRv2-S"


################################
# 3. Run locally #
################################
# Run the following command in the terminal:
# PYTHONPATH="${PWD}:${PYTHONPATH}" \
# python ./supervisely_integration/serve/main.py \
# --model "models/392_RT-DETRv2/checkpoints/best.pth"
# --model "RT-DETRv2-S"

###################################
# How to use the serving session: #
###################################

# Connect to the serving session
session = sly.nn.inference.Session(api, session_url="http://0.0.0.0:8000")

img_path = "supervisely_integration/demo/img/coco_sample.jpg"
ann = session.inference_image_path(img_path)

# Display the annotated image
img_preview_path = "supervisely_integration/demo/img/coco_sample_ann_preview.jpg"

if os.path.exists(img_preview_path):
os.remove(img_preview_path)

# Read the image and draw the annotation
img = sly.image.read(img_path)
ann.draw_pretty(img)
sly.image.write(img_preview_path, img)
4 changes: 2 additions & 2 deletions supervisely_integration/train/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"icon_cover": true,
"poster": "https://github.com/user-attachments/assets/b4554de5-3d2c-4b4f-aba9-95864cb05289",
"description": "Train RT-DETRv2 model on your data",
"docker_image": "supervisely/rt-detrv2:1.0.8",
"instance_version": "6.12.28",
"docker_image": "supervisely/rt-detrv2:1.0.9",
"instance_version": "6.12.29",
"task_location": "workspace_tasks",
"need_gpu": true,
"gpu": "required",
Expand Down

0 comments on commit 65ed522

Please sign in to comment.