Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
SAM_pytorch
Commits
02c1f84e
"...text-generation-inference.git" did not exist on "ccd5725a0c0b2ef151d317c86d1f52ad038bbae9"
Commit
02c1f84e
authored
Oct 12, 2023
by
yuhai
Browse files
Update README.md
parent
5273df61
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
8 deletions
+24
-8
README.md
README.md
+24
-8
No files found.
README.md
View file @
02c1f84e
# SAM
# SAM
## 论文
## 论文
Segment Anything
Segment Anything
-
https://scontent-sin6-4.xx.fbcdn.net/v/t39.2365-6/10000000_900554171201033_1602411987825904100_n.pdf?_nc_cat=100&ccb=1-7&
_nc_
sid=3c67a6&
_nc_
ohc=3lEwwwRVaDkAX_j-2jP&
_nc_
ht=scontent-sin6-4.xx&oh=00_AfA1Y7gU67MmSiOb3vgzM2eTEzqZ92zTbbbQx8A-bTD5iw&oe=652C3227
-
https://arxiv.org/abs/2304.02643
## 模型结构
## 模型结构


...
@@ -20,7 +19,6 @@ Segment Anything
...
@@ -20,7 +19,6 @@ Segment Anything
解码器设计如图所示。使用两个转置卷积层将更新的图像嵌入放大4倍(现在相对于输入图像缩小了4倍)。将更新的输出token嵌入传递给一个小的3层MLP,它输出一个与扩展的图像嵌入的通道维度匹配的向量。最后,使用扩展的图像嵌入和MLP的输出进行空间点乘,预测出一个掩码。Transformer使用256的嵌入维度。在64×64图像嵌入的交叉注视层中,查询、键和值通道维度为128。所有注意力层都使用8个头。用于放大输出图像嵌入的转置卷积是2×2,步幅2,输出通道维度为64和32,并具有GELU激活。它们通过层归一化来分隔。
解码器设计如图所示。使用两个转置卷积层将更新的图像嵌入放大4倍(现在相对于输入图像缩小了4倍)。将更新的输出token嵌入传递给一个小的3层MLP,它输出一个与扩展的图像嵌入的通道维度匹配的向量。最后,使用扩展的图像嵌入和MLP的输出进行空间点乘,预测出一个掩码。Transformer使用256的嵌入维度。在64×64图像嵌入的交叉注视层中,查询、键和值通道维度为128。所有注意力层都使用8个头。用于放大输出图像嵌入的转置卷积是2×2,步幅2,输出通道维度为64和32,并具有GELU激活。它们通过层归一化来分隔。
## 算法原理
## 算法原理
SAM分为图像编码器和快速提示编码器/掩码解码器,可以重用相同的image embedding图像嵌入(并摊销其成本)与不同的提示。给定image embedding图像嵌入,提示编码器和掩码解码器可以在web浏览器中预测掩码。为了使SAM实现模糊感知,设计它来预测单个提示的多个掩码,从而使SAM能够自然地处理模糊性。
SAM分为图像编码器和快速提示编码器/掩码解码器,可以重用相同的image embedding图像嵌入(并摊销其成本)与不同的提示。给定image embedding图像嵌入,提示编码器和掩码解码器可以在web浏览器中预测掩码。为了使SAM实现模糊感知,设计它来预测单个提示的多个掩码,从而使SAM能够自然地处理模糊性。
## 环境配置
## 环境配置
...
@@ -28,12 +26,22 @@ SAM分为图像编码器和快速提示编码器/掩码解码器,可以重用
...
@@ -28,12 +26,22 @@ SAM分为图像编码器和快速提示编码器/掩码解码器,可以重用
从
[
光源
](
https://www.sourcefind.cn/#/service-list
)
拉取镜像
从
[
光源
](
https://www.sourcefind.cn/#/service-list
)
拉取镜像
```
```
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.10.0-centos7.6-dtk-22.10-py39-latest
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.10.0-centos7.6-dtk-22.10-py39-latest
docker run -it --network=host --name=SAM_pytorch --privileged --device=/dev/kfd --device=/dev/dri --ipc=host --shm-size=16G --group-add video --cap-add=SYS_PTRACE <上面获得的镜像ID> /bin/bash
```
```
安装其他依赖:
安装其他依赖:
```
```
pip install opencv-python pycocotools matplotlib onnxruntime onnx
pip install opencv-python pycocotools matplotlib onnxruntime onnx
```
```
### Anaconda(方法二)
### Dockerfile(方法二)
```
docker build --no-cache -t image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.10.0-centos7.6-dtk-22.10-py39-latest .
docker run -it --network=host --name=SAM_pytorch --privileged --device=/dev/kfd --device=/dev/dri --ipc=host --shm-size=16G --group-add video --cap-add=SYS_PTRACE <上面获得的镜像ID> /bin/bash
```
安装其他依赖:
```
pip install opencv-python pycocotools matplotlib onnxruntime onnx
```
### Anaconda(方法三)
直接使用pip install的方式安装
直接使用pip install的方式安装
```
```
pip install git+https://github.com/facebookresearch/segment-anything.git
pip install git+https://github.com/facebookresearch/segment-anything.git
...
@@ -46,11 +54,19 @@ cd segment-anything; pip install -e .
...
@@ -46,11 +54,19 @@ cd segment-anything; pip install -e .
## 数据集
## 数据集
数据集名称:SA-1B Dataset
数据集名称:SA-1B Dataset
完整数据集可在
[
这里
](
https://ai.facebook.com/datasets/segment-anything-downloads/
)
进行下载
完整数据集可在
[
这里
](
https://ai.facebook.com/datasets/segment-anything-downloads/
)
进行下载
项目中用于试验训练的迷你数据集见./notebooks/images
项目中用于试验训练的迷你数据集结构如下
```
── notebooks
│ ├── images
│ │ ├── dog.jpg
│ │ ├── groceries.jpg
│ │ └── trunk.jpg
```
## 微调
## 微调
官网提供了生成掩码的预训练权重和生成掩码的脚本,没有提供训练脚本,但可使用第三方提供的示例脚本微调
官网提供了生成掩码的预训练权重和生成掩码的脚本,没有提供训练脚本,但可使用第三方提供的示例脚本微调
如果您有兴趣,参考
[
这里
](
https://github.com/luca-medeiros/lightning-sam/blob/main/lightning_sam/train.py
)
如果您有兴趣,参考
[
这里
](
https://github.com/luca-medeiros/lightning-sam/blob/main/lightning_sam/train.py
)
###单机单卡
###单机单卡
```
```
git clone https://github.com/luca-medeiros/lightning-sam.git
git clone https://github.com/luca-medeiros/lightning-sam.git
...
@@ -63,7 +79,7 @@ python train.py
...
@@ -63,7 +79,7 @@ python train.py
```
```
python scripts/amg.py --checkpoint <path/to/checkpoint> --model-type <model_type> --input <image_or_folder> --output <path/to/output>
python scripts/amg.py --checkpoint <path/to/checkpoint> --model-type <model_type> --input <image_or_folder> --output <path/to/output>
```
```
注:checkpoint预训练模型在
[
这里
](
https://
github.com/search?q=
segment
-
anything
&type=repositories#model-checkpoints
)
下载
注:checkpoint预训练模型在
[
这里
](
https://
dl.fbaipublicfiles.com/
segment
_
anything
/sam_vit_h_4b8939.pth
)
下载
指令中:
<path
/
to
/
checkpoint
>
代表选择权重的路径
指令中:
<path
/
to
/
checkpoint
>
代表选择权重的路径
...
@@ -87,10 +103,10 @@ python scripts/amg.py --checkpoint <path/to/checkpoint> --model-type <model_type
...
@@ -87,10 +103,10 @@ python scripts/amg.py --checkpoint <path/to/checkpoint> --model-type <model_type
掩码生成的部分结果在同级目录outputs中可以查看,结果示例如上图,官方提供demo可在
[
这里
](
https://segment-anything.com/demo
)
试用
掩码生成的部分结果在同级目录outputs中可以查看,结果示例如上图,官方提供demo可在
[
这里
](
https://segment-anything.com/demo
)
试用
## 应用场景
## 应用场景
### 算法类别
### 算法类别
视觉算法:
图像分割
图像分割
### 热点应用行业
### 热点应用行业
SAM算法能智能抠图,可以用于识别图像和视频中的物体,具有广泛的通用性。SAM作为开源且更通用AI系统的强大组件,赋能工业、煤矿、医学影像、安防监控等多场景。
SAM算法能智能抠图,可以用于识别图像和视频中的物体,具有广泛的通用性。SAM作为开源且更通用AI系统的强大组件,赋能工业、煤矿、医学影像、安防监控等多场景。
热点应用行业:能源
、
医疗
、
网安
热点应用行业:能源
,
医疗
,
网安
## 源码仓库及问题反馈
## 源码仓库及问题反馈
https://developer.hpccube.com/codes/modelzoo/sam_pytorch
https://developer.hpccube.com/codes/modelzoo/sam_pytorch
## 参考资料
## 参考资料
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment