diff --git a/.vscode/launch.json b/.vscode/launch.json index 5a826496cc1f..7cb46d0c698d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,7 @@ "env": { "LOG_LEVEL": "DEBUG", "PYTHONPATH": "${workspaceFolder}:${PYTHONPATH}", + "SLY_APP_DATA_DIR": "${workspaceFolder}/results", } }, { @@ -35,13 +36,8 @@ "PYTHONPATH": "${workspaceFolder}:${PYTHONPATH}", "LOG_LEVEL": "DEBUG", "ENV": "production", - "TEAM_ID": "277", - "WORKSPACE_ID": "403", "DEBUG_WITH_SLY_NET": "1", "SLY_APP_DATA_DIR": "${workspaceFolder}/results", - "modal.state.modelWeightsOptions": "pretrained", - "modal.state.selectedModel": "YOLOv5s", - "modal.state.weightsPath": "" } } ] diff --git a/requirements.txt b/requirements.txt index 489a8b43bb5f..94d179bfd9d3 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # pip install -r requirements.txt -supervisely==6.69.15 +supervisely==6.69.70 opencv-python-headless==4.5.5.62 opencv-python==4.5.5.62 diff --git a/supervisely/serve/local.env b/supervisely/serve/local.env index 7e2d09608b87..67c36abf293d 100644 --- a/supervisely/serve/local.env +++ b/supervisely/serve/local.env @@ -1,13 +1,11 @@ PYTHONUNBUFFERED=1 APP_NAME="Serve YOLOv5" -SLY_APP_DATA_DIR="./data_dir" -LOG_LEVEL="trace" -context.teamId=277 -context.workspaceId=403 +TEAM_ID=440 +WORKSPACE_ID=662 +# "pretrained" or "custom" modal.state.modelWeightsOptions="pretrained" -#"pretrained" "custom" modal.state.selectedModel="YOLOv5s" modal.state.weightsPath="" diff --git a/supervisely/serve/src/main.py b/supervisely/serve/src/main.py index 09916f4051ac..09caa686d60a 100644 --- a/supervisely/serve/src/main.py +++ b/supervisely/serve/src/main.py @@ -26,17 +26,21 @@ pretrained_weights = os.environ['modal.state.selectedModel'].lower() custom_weights = os.environ['modal.state.weightsPath'] +pretrained_weights_url = f"https://github.com/ultralytics/yolov5/releases/download/v5.0/{pretrained_weights}.pt" + class YOLOv5Model(sly.nn.inference.ObjectDetection): def load_on_device( self, + model_dir: str = None, device: Literal["cpu", "cuda", "cuda:0", "cuda:1", "cuda:2", "cuda:3"] = "cpu", ): # download weights if model_weights_options == "pretrained": - self.local_weights_path = self.location + self.local_weights_path = self.download(pretrained_weights_url) if model_weights_options == "custom": - self.local_weights_path = self.location[0] - configs_local_path = self.location[1] + self.local_weights_path = self.download(custom_weights) + cfg_path_in_teamfiles = os.path.join(Path(custom_weights).parents[1], 'opt.yaml') + configs_local_path = self.download(cfg_path_in_teamfiles) self.device = select_device(device) self.half = self.device.type != 'cpu' # half precision only supported on CUDA @@ -138,7 +142,6 @@ def predict( return predictions - def predict_raw( self, image_path: str, settings: Dict[str, Any] ) -> List[sly.nn.PredictionBBox]: @@ -188,20 +191,11 @@ def predict_raw( device = "cuda" if torch.cuda.is_available() else "cpu" print("Using device:", device) -if model_weights_options == "pretrained": - location = f"https://github.com/ultralytics/yolov5/releases/download/v5.0/{pretrained_weights}.pt" -elif model_weights_options == "custom": - location = [ - custom_weights, # model weights - os.path.join(Path(custom_weights).parents[1], 'opt.yaml') # model config - ] - m = YOLOv5Model( - location=location, custom_inference_settings=os.path.join(app_source_path, "custom_settings.yaml"), sliding_window_mode = "advanced" ) -m.load_on_device(device) +m.load_on_device(device=device) if sly.is_production(): # this code block is running on Supervisely platform in production