Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Supervisely version to v6.73.100 #49

Merged
merged 6 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
tag_version:
description: "Docker Image Tag"
description: 'Docker Image Tag (without "v")'
required: true
default: ""

Expand All @@ -23,16 +23,16 @@ jobs:
docker-images: false
swap-storage: true
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
push: true
file: docker/Dockerfile
Expand Down
9 changes: 2 additions & 7 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
supervisely==6.73.96
supervisely==6.73.100

openmim
ffmpeg-python==0.2.0
pyyaml==6.0

# torch==1.13.0
# torchvision==0.14.0

# mmcv-full==1.7.0
# mmsegmentation==0.29.1
# mmcls==0.24.1
# yapf==0.40.1
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ RUN pip3 install mmcv-full==1.4.4 -f https://download.openmmlab.com/mmcv/dist/cu
RUN pip3 install mmsegmentation==0.23.0
RUN pip3 install mmcls==0.21.0
RUN pip3 install pyyaml==6.0
RUN pip3 install yapf==0.40.1

# RUN pip3 install torch==1.13.0
# RUN pip3 install torchvision==0.14.0
RUN pip3 install ffmpeg-python==0.2.0

COPY dev_requirements.txt dev_requirements.txt
RUN pip3 install -r dev_requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion serve/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"serve"
],
"description": "Deploy model as REST API service",
"docker_image": "supervisely/mmseg:1.3.7",
"docker_image": "supervisely/mmseg:1.3.9",
"instance_version": "6.8.88",
"entrypoint": "python -m uvicorn main:m.app --app-dir ./serve/src --host 0.0.0.0 --port 8000 --ws websockets",
"port": 8000,
Expand Down
14 changes: 14 additions & 0 deletions serve/dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# git+https://github.com/supervisely/supervisely.git@some-test-branch

supervisely==6.73.100

openmim
ffmpeg-python==0.2.0
pyyaml==6.0

torch==1.13.0
torchvision==0.14.0

mmcv-full==1.7.0
mmsegmentation==0.29.1
mmcls==0.24.1
93 changes: 58 additions & 35 deletions serve/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@

import supervisely as sly
from serve.src import utils
from supervisely.app.widgets import (CustomModelsSelector,
PretrainedModelsSelector, RadioTabs,
Widget)
from supervisely.nn.artifacts.mmsegmentation import MMSegmentation
from supervisely.app.widgets import (
CustomModelsSelector,
PretrainedModelsSelector,
RadioTabs,
Widget,
)
from supervisely.io.fs import silent_remove

root_source_path = str(Path(__file__).parents[2])
Expand All @@ -43,12 +47,14 @@
models_meta_path = os.path.join(root_source_path, "models", "model_meta.json")

# for local debug
selected_checkpoint = None
selected_checkpoint = None
selected_model_name = None


def str_to_class(classname):
return getattr(sys.modules[__name__], classname)


configs_dir = os.path.join(root_source_path, "configs")
mmseg_ver = pkg_resources.get_distribution("mmsegmentation").version
if os.path.isdir(f"/tmp/mmseg/mmsegmentation-{mmseg_ver}"):
Expand All @@ -66,7 +72,8 @@ def initialize_custom_gui(self) -> Widget:
models = self.get_models()
filtered_models = utils.filter_models_structure(models)
self.pretrained_models_table = PretrainedModelsSelector(filtered_models)
custom_models = sly.nn.checkpoints.mmsegmentation.get_list(api, team_id)
sly_mmseg = MMSegmentation(team_id)
custom_models = sly_mmseg.get_list()
self.custom_models_table = CustomModelsSelector(
team_id,
custom_models,
Expand Down Expand Up @@ -114,17 +121,19 @@ def load_model_meta(
self, model_source: str, cfg: Config, checkpoint_name: str = None, arch_type: str = None
):
def set_common_meta(classes, palette):
obj_classes = [sly.ObjClass(name, sly.Bitmap, color) for name, color in zip(classes, palette)]
obj_classes = [
sly.ObjClass(name, sly.Bitmap, color) for name, color in zip(classes, palette)
]
self.checkpoint_name = checkpoint_name
self.dataset_name = cfg.dataset_type
self.class_names = classes
self._model_meta = sly.ProjectMeta(obj_classes=sly.ObjClassCollection(obj_classes))
self._get_confidence_tag_meta()

if model_source == "Custom models":
self.selected_model_name = cfg.pretrained_model
self.selected_model_name = cfg.pretrained_model
classes = cfg.checkpoint_config.meta.CLASSES
palette = cfg.checkpoint_config.meta.PALETTE
palette = cfg.checkpoint_config.meta.PALETTE
set_common_meta(classes, palette)

elif model_source == "Pretrained models":
Expand All @@ -137,7 +146,6 @@ def set_common_meta(classes, palette):
self.model.CLASSES = classes
self.model.PALETTE = palette


def load_model(
self,
device: Literal["cpu", "cuda", "cuda:0", "cuda:1", "cuda:2", "cuda:3"],
Expand Down Expand Up @@ -199,45 +207,50 @@ def load_model(
cfg = Config.fromfile(local_config_path)
cfg.model.pretrained = None
cfg.model.train_cfg = None
self.model = build_segmentor(cfg.model, test_cfg=cfg.get('test_cfg'))
checkpoint = load_checkpoint(self.model, local_weights_path, map_location='cpu')

self.model = build_segmentor(cfg.model, test_cfg=cfg.get("test_cfg"))
checkpoint = load_checkpoint(self.model, local_weights_path, map_location="cpu")

self.load_model_meta(model_source, cfg, checkpoint_name, arch_type)

self.model.cfg = cfg # save the config in the model for convenience
self.model.to(device)
self.model.eval()
self.model = revert_sync_batchnorm(self.model)

except KeyError as e:
raise KeyError(f"Error loading config file: {local_config_path}. Error: {e}")

def load_on_device(
self,
model_dir: str,
model_dir: str,
device: Literal["cpu", "cuda", "cuda:0", "cuda:1", "cuda:2", "cuda:3"] = "cpu",
) -> None:
self.device = device
if self.gui is not None:
model_source = self.gui.get_model_source()
if model_source == "Pretrained models":
selected_model = self.gui.get_checkpoint_info()
weights_path, config_path = self.download_pretrained_files(selected_model, model_dir)
weights_path, config_path = self.download_pretrained_files(
selected_model, model_dir
)
elif model_source == "Custom models":
custom_weights_link = self.gui.get_custom_link()
weights_path, config_path = self.download_custom_files(custom_weights_link, model_dir)
weights_path, config_path = self.download_custom_files(
custom_weights_link, model_dir
)
else:
# for local debug only
model_source = "Pretrained models"
weights_path, config_path = self.download_pretrained_files(selected_checkpoint, model_dir)


weights_path, config_path = self.download_pretrained_files(
selected_checkpoint, model_dir
)

cfg = Config.fromfile(config_path)
cfg.model.pretrained = None
cfg.model.train_cfg = None
model = build_segmentor(cfg.model, test_cfg=cfg.get('test_cfg'))
checkpoint = load_checkpoint(model, weights_path, map_location='cpu')
model = build_segmentor(cfg.model, test_cfg=cfg.get("test_cfg"))
checkpoint = load_checkpoint(model, weights_path, map_location="cpu")
if model_source == "Custom models":
classes = cfg.checkpoint_config.meta.CLASSES
palette = cfg.checkpoint_config.meta.PALETTE
Expand Down Expand Up @@ -267,7 +280,9 @@ def load_on_device(
self.model = model
self.class_names = classes

obj_classes = [sly.ObjClass(name, sly.Bitmap, color) for name, color in zip(classes, palette)]
obj_classes = [
sly.ObjClass(name, sly.Bitmap, color) for name, color in zip(classes, palette)
]
self._model_meta = sly.ProjectMeta(obj_classes=sly.ObjClassCollection(obj_classes))
print(f"✅ Model has been successfully loaded on {device.upper()} device")

Expand All @@ -285,33 +300,39 @@ def get_models(self):
for model_meta in model_yamls:
mmseg_ver = pkg_resources.get_distribution("mmsegmentation").version
model_yml_url = f"https://github.com/open-mmlab/mmsegmentation/tree/v{mmseg_ver}/configs/{model_meta['yml_file']}"
model_yml_local = os.path.join(configs_dir, model_meta['yml_file'])
model_yml_local = os.path.join(configs_dir, model_meta["yml_file"])
with open(model_yml_local, "r") as stream:
model_info = yaml.safe_load(stream)
model_config[model_meta["model_name"]] = {}
model_config[model_meta["model_name"]]["checkpoints"] = []
model_config[model_meta["model_name"]]["paper_from"] = model_meta["paper_from"]
model_config[model_meta["model_name"]]["year"] = model_meta["year"]
model_config[model_meta["model_name"]]["config_url"] = os.path.dirname(model_yml_url)
model_config[model_meta["model_name"]]["config_url"] = os.path.dirname(
model_yml_url
)
for model in model_info["Models"]:
checkpoint_info = OrderedDict()
checkpoint_info["Model"] = model["Name"]
checkpoint_info["Backbone"] = model["Metadata"]["backbone"]
checkpoint_info["Method"] = model["In Collection"]
checkpoint_info["Dataset"] = model["Results"][0]["Dataset"]
try:
checkpoint_info["Inference Time (ms/im)"] = model["Metadata"]["inference time (ms/im)"][0]["value"]
checkpoint_info["Inference Time (ms/im)"] = model["Metadata"][
"inference time (ms/im)"
][0]["value"]
except KeyError:
checkpoint_info["Inference Time (ms/im)"] = "-"
checkpoint_info["Input Size (H, W)"] = model["Metadata"]["crop size"]
checkpoint_info["LR scheduler (steps)"] = model["Metadata"]["lr schd"]
try:
checkpoint_info["Memory (Training, GB)"] = model["Metadata"]["Training Memory (GB)"]
checkpoint_info["Memory (Training, GB)"] = model["Metadata"][
"Training Memory (GB)"
]
except KeyError:
checkpoint_info["Memory (Training, GB)"] = "-"
for metric_name, metric_val in model["Results"][0]["Metrics"].items():
checkpoint_info[metric_name] = metric_val
#checkpoint_info["config_file"] = os.path.join(f"https://github.com/open-mmlab/mmsegmentation/tree/v{mmseg_ver}", model["Config"])
# checkpoint_info["config_file"] = os.path.join(f"https://github.com/open-mmlab/mmsegmentation/tree/v{mmseg_ver}", model["Config"])
checkpoint_info["meta"] = {
"task_type": None,
"arch_type": None,
Expand All @@ -335,10 +356,13 @@ def predict(


if sly.is_production():
sly.logger.info("Script arguments", extra={
"context.teamId": sly.env.team_id(),
"context.workspaceId": sly.env.workspace_id(),
})
sly.logger.info(
"Script arguments",
extra={
"context.teamId": sly.env.team_id(),
"context.workspaceId": sly.env.workspace_id(),
},
)

m = MMSegmentationModel(use_gui=True)

Expand All @@ -360,4 +384,3 @@ def predict(
vis_path = "./demo_data/image_01_prediction.jpg"
m.visualize(results, image_path, vis_path, thickness=0)
print(f"predictions and visualization have been saved: {vis_path}")

64 changes: 31 additions & 33 deletions train/config.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
{
"name": "Train MMSegmentation",
"type": "app",
"categories": [
"neural network",
"images",
"videos",
"semantic segmentation",
"segmentation & tracking",
"train"
],
"description": "Dashboard to configure, start and monitor training",
"docker_image": "supervisely/mmseg:1.3.4",
"min_instance_version": "6.8.48",
"main_script": "train/src/main.py",
"gui_template": "train/src/gui.html",
"task_location": "workspace_tasks",
"need_gpu": true,
"gpu": "required",
"isolate": true,
"icon": "https://i.imgur.com/GaEFmkH.png",
"icon_cover": true,
"context_menu": {
"target": [
"images_project"
],
"context_root": "Neural Networks",
"context_category": "MM Segmentation"
},
"poster": "https://user-images.githubusercontent.com/48245050/182847473-9a35f213-c27b-4abd-bd64-c73bf80fb056.jpg",
"community_agent": false,
"license": {
"type": "Apache-2.0"
}
"name": "Train MMSegmentation",
"type": "app",
"categories": [
"neural network",
"images",
"videos",
"semantic segmentation",
"segmentation & tracking",
"train"
],
"description": "Dashboard to configure, start and monitor training",
"docker_image": "supervisely/mmseg:1.3.9",
"min_instance_version": "6.8.48",
"main_script": "train/src/main.py",
"gui_template": "train/src/gui.html",
"task_location": "workspace_tasks",
"need_gpu": true,
"gpu": "required",
"isolate": true,
"icon": "https://i.imgur.com/GaEFmkH.png",
"icon_cover": true,
"context_menu": {
"target": ["images_project"],
"context_root": "Neural Networks",
"context_category": "MM Segmentation"
},
"poster": "https://user-images.githubusercontent.com/48245050/182847473-9a35f213-c27b-4abd-bd64-c73bf80fb056.jpg",
"community_agent": false,
"license": {
"type": "Apache-2.0"
}
}
14 changes: 14 additions & 0 deletions train/dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# git+https://github.com/supervisely/supervisely.git@some-test-branch

supervisely==6.73.100

openmim
ffmpeg-python==0.2.0
pyyaml==6.0

torch==1.13.0
torchvision==0.14.0

mmcv-full==1.7.0
mmsegmentation==0.29.1
mmcls==0.24.1
1 change: 0 additions & 1 deletion train/requirements.txt

This file was deleted.

Loading