Skip to content

Commit

Permalink
support SAM-Med2D
Browse files Browse the repository at this point in the history
  • Loading branch information
CVHub520 committed Sep 6, 2023
1 parent 3267823 commit 7d8fe5b
Show file tree
Hide file tree
Showing 11 changed files with 1,898 additions and 22 deletions.
3 changes: 2 additions & 1 deletion README_us-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ English | [简体中文](README_zh-CN.md)
- Segment Anything Model
- [SAM](https://arxiv.org/abs/2304.02643): Universal model for natural image segmentation;
- [MobileSAM](https://arxiv.org/abs/2306.14289): Faster version of `SAM`;
- [SAM-Med2D](https://github.com/OpenGVLab/SAM-Med2D): 2D Universal model for medical image segmentation (🤗);
- [MedSAM](https://arxiv.org/abs/2304.12306): Universal model for medical image segmentation;
- [LVMSAM](https://arxiv.org/abs/2306.11925)
- [BUID](https://github.com/CVHub520/X-AnyLabeling/tree/main/assets/examples/buid): Ultrasound breast cancer segmentation model;
Expand Down Expand Up @@ -65,7 +66,7 @@ English | [简体中文](README_zh-CN.md)

### 1.1 Executable

- Download and run the `GUI` version directly from [Baidu Cloud (Access Code: bkdj)](https://pan.baidu.com/s/1cJeRE2wdiYDy05pb5_JqYQ?pwd=bkdj).
- Download and run the `GUI` version directly from [Release tag-v0.2.1](https://github.com/CVHub520/X-AnyLabeling/releases/tag/v0.2.1).

Note:
- For MacOS:
Expand Down
5 changes: 3 additions & 2 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div align="center">


[帮助文档](./docs/Q&A.md)
👉[帮助文档](./docs/Q&A.md)👈

简体中文 | [English](README_us-EN.md)

Expand All @@ -41,6 +41,7 @@
- Segment Anything Model
- [SAM](https://arxiv.org/abs/2304.02643): 通用自然图像分割一切模型;
- [MobileSAM](https://arxiv.org/abs/2306.14289): 快速版 `SAM`
- [SAM-Med2D](https://github.com/OpenGVLab/SAM-Med2D): 2D医学图像分割一切模型(🤗推荐);
- [MedSAM](https://arxiv.org/abs/2304.12306): 通用医学图像分割一切模型;
- [LVMSAM](https://arxiv.org/abs/2306.11925)
- [BUID](https://github.com/CVHub520/X-AnyLabeling/tree/main/assets/examples/buid): 超声乳腺癌分割模型;
Expand Down Expand Up @@ -69,7 +70,7 @@

### 1.1 可执行文件

-[百度网盘(提取码: bkdj)](https://pan.baidu.com/s/1cJeRE2wdiYDy05pb5_JqYQ?pwd=bkdj)下载并运行`GUI`版本直接运行。
-[百度网盘(提取码: cn0c)](https://pan.baidu.com/s/1HeEoVc-_DI5EuSU3MipqJQ?pwd=cn0c)下载并运行`GUI`版本直接运行。

注意:
- 对于MacOS:
Expand Down
2 changes: 1 addition & 1 deletion anylabeling/app_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__appname__ = "X-AnyLabeling"
__appdescription__ = "Advanced Auto Labeling Solution with Added Features"
__version__ = "0.2.0"
__version__ = "0.2.1"
__preferred_device__ = "CPU" # GPU or CPU
20 changes: 11 additions & 9 deletions anylabeling/configs/auto_labeling/models.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- model_name: "sam_med2d_vit_b-r20230901"
config_file: ":/sam_med2d_vit_b.yaml"
- model_name: "segment_anything_vit_b_quant-r20230810"
config_file: ":/segment_anything_vit_b_quant.yaml"
- model_name: "segment_anything_vit_b-r20230810"
Expand Down Expand Up @@ -28,6 +30,14 @@
config_file: ":/medsam_vit_b_quant.yaml"
- model_name: "mobile_sam_vit_h-r20230810"
config_file: ":/mobile_sam_vit_h.yaml"
- model_name: "clrnet_tusimple_r18-r20230901"
config_file: ":/clrnet_tusimple_r18.yaml"
- model_name: "yolox_l_dwpose_ucoco-r20230820"
config_file: ":/yolox_l_dwpose_ucoco.yaml"
- model_name: "rtdetr_r50-r20230520"
config_file: ":/rtdetr_r50.yaml"
- model_name: "yolov5s_resnet50-r20230520"
config_file: ":/yolov5s_resnet50.yaml"
- model_name: "yolov5n-r20230520"
config_file: ":/yolov5n.yaml"
- model_name: "yolov5s-r20230520"
Expand Down Expand Up @@ -81,12 +91,4 @@
- model_name: "yolo-nas-m-r20230615"
config_file: ":/yolo_nas_m.yaml"
- model_name: "yolo-nas-l-r20230615"
config_file: ":/yolo_nas_l.yaml"
- model_name: "yolov5s_resnet50-r20230520"
config_file: ":/yolov5s_resnet50.yaml"
- model_name: "rtdetr_r50-r20230520"
config_file: ":/rtdetr_r50.yaml"
- model_name: "yolox_l_dwpose_ucoco-r20230820"
config_file: ":/yolox_l_dwpose_ucoco.yaml"
- model_name: "clrnet_tusimple_r18-r20230901"
config_file: ":/clrnet_tusimple_r18.yaml"
config_file: ":/yolo_nas_l.yaml"
6 changes: 6 additions & 0 deletions anylabeling/configs/auto_labeling/sam_med2d_vit_b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: sam_med2d
name: sam-med2d_vit_b-r20230901
display_name: SAM-Med2D-256x (ViT-Base)
encoder_model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v0.2.0/sam-med2d_b.encoder.onnx
decoder_model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v0.2.0/sam-med2d_b.decoder.onnx
input_size: 256
2 changes: 1 addition & 1 deletion anylabeling/services/auto_labeling/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class Model(QObject):
BASE_DOWNLOAD_URL = (
"https://github.com/CVHub520/X-AnyLabeling/releases/tag/v0.2.0"
"https://github.com/CVHub520/X-AnyLabeling/releases/tag/v0.2.1"
)

class Meta(QObject):
Expand Down
32 changes: 28 additions & 4 deletions anylabeling/services/auto_labeling/model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ def load_custom_model(self, config_file):
or "name" not in model_config
or model_config["type"]
not in [
"segment_anything",
"segment_anything",
"sam_med2d",
"yolov5",
"yolov6",
"yolov7",
Expand Down Expand Up @@ -455,7 +456,30 @@ def _load_model(self, model_id):
)
)
return
# Request next files for prediction
self.request_next_files_requested.emit()
elif model_config["type"] == "sam_med2d":
from .sam_med2d import SAM_Med2D

try:
model_config["model"] = SAM_Med2D(
model_config, on_message=self.new_model_status.emit
)
self.auto_segmentation_model_selected.emit()
except Exception as e: # noqa
print(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
self.new_model_status.emit(
self.tr(
"Error in loading model: {error_message}".format(
error_message=str(e)
)
)
)
return
# Request next files for prediction
self.request_next_files_requested.emit()
elif model_config["type"] == "yolov5_cls":
Expand Down Expand Up @@ -580,7 +604,7 @@ def set_auto_labeling_marks(self, marks):
"""
if (
self.loaded_model_config is None
or self.loaded_model_config["type"] != "segment_anything"
or self.loaded_model_config["type"] not in ["segment_anything", "sam_med2d"]
):
return
self.loaded_model_config["model"].set_auto_labeling_marks(marks)
Expand Down Expand Up @@ -666,8 +690,8 @@ def on_next_files_changed(self, next_files):
if self.loaded_model_config is None:
return

# Currently only segment_anything model supports this feature
if self.loaded_model_config["type"] != "segment_anything":
# Currently only segment_anything-like model supports this feature
if self.loaded_model_config["type"] not in ["segment_anything", "sam_med2d"]:
return

self.loaded_model_config["model"].on_next_files_changed(next_files)
Loading

0 comments on commit 7d8fe5b

Please sign in to comment.