"vscode:/vscode.git/clone" did not exist on "27e327b415cfd009ce1cf747b3fc0a1bbe7ee15b"
README.md 3.07 KB
Newer Older
dengjb's avatar
dengjb committed
1
2
# FastSAM_pytorch

dengjb's avatar
dengjb committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
## 论文

[论文](https://arxiv.org/pdf/2306.12156.pdf)

## 模型结构

以yolov8-seg的instance segmentation为基础,检测时集成instance segmentation分支,主要分为两步全实例分割(all instance Segmentation)和基于prompt的mask输出(Prompt-guided Selection),仅使用了2%的SA-1B数据集便得到了差不多的精度但快几十倍的速度。

![Overview.png](assets%2FOverview.png)

## 算法原理
该算法采用yolov8-seg的instance segmentation为基础,检测时集成instance segmentation分支实现。

![11.png](resources%2F11.png)

## 环境配置

### Docker (方法一)

```
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk23.10-py38
# <your IMAGE ID>为以上拉取的docker的镜像ID替换
docker run -it -v /path/your_code_data/:/path/your_code_data/ --shm-size=32G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash
cd /path/workspace/
pip3 install -r requirements.txt
pip3 install git+https://github.com/openai/CLIP.git
```

### Dockerfile (方法二)

```
cd ./docker
docker build --no-cache -t crnn_pytorch:last .
# <your IMAGE ID>为以上拉取的docker的镜像ID替换
docker run -it -v /path/your_code_data/:/path/your_code_data/ --shm-size=32G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash
```

### Anaconda (方法三)

1、关于本项目DCU显卡所需的特殊深度学习库可从光合开发者社区下载安装: https://developer.hpccube.com/tool/

```
DTK软件栈:dtk22.10
python:python3.8
pytorch:1.10.0
torchvision:0.10.0
```

Tips:以上dtk软件栈、python、pytorch等DCU相关工具版本需要严格一一对应

2、其他非特殊库直接按照requirements.txt安装

```
pip3 install -r requirements.txt
pip3 install git+https://github.com/openai/CLIP.git
```



## 数据集

训练数据集为SA-1B的2%左右的数据量,由于数据量过大,且官方并未放出2%的具体数据集,以下数据集为SA-1B原始数据集,训练仅供参考。

[训练数据](https://ai.meta.com/datasets/segment-anything/)


## 训练



## 推理

#### 单卡推理
[权重下载地址](https://pan.baidu.com/s/18KzBmOTENjByoWWR17zdiQ?pwd=0000)
```
HIP_VISIBLE_DEVICES=1 python Inference.py --model_path ./weights/FastSAM-x.pt --img_path ./images/dogs.jpg
```
## result
此处以Fast-SAM-x模型进行推理测试<br>

| 输入 | 输出 |
|:--:|:-:|
|  ![dogs.jpg](images%2Fdogs.jpg)  |![dogs.jpg](output%2Fdogs.jpg)|

### 精度
#### Instance Segmentation On COCO 2017

|  method  |  AP  | APS  | APM  | APL  |
| :------: | :--: | :--: | :--: | :--: |
| ViTDet-H | .510 | .320 | .543 | .689 |
|   SAM    | .465 | .308 | .510 | .617 |
| FastSAM  | .379 | .239 | .434 | .500 |


## 应用场景
### 算法分类
图像分割

### 热点应用行业
制造,广媒,能源,医疗,家居,教育

## 源码仓库及问题反馈

https://developer.hpccube.com/codes/modelzoo/fastsam_pytorch

## 参考资料

[GitHub - Fast-SAM](https://github.com/CASIA-IVA-Lab/FastSAM?tab=readme-ov-file)