修复第一次点击sam无法标注的问题

This commit is contained in:
copper 2023-09-12 21:52:44 +08:00
parent f4b994d30b
commit 3c5e85df23
7 changed files with 2271 additions and 21 deletions

View File

@ -1,4 +1,5 @@
# ISAT with segment anything
# 交互式半自动图像分割标注工具
![标注.gif](./display/标注.gif)
@ -17,6 +18,7 @@
Demo Video[youtube](https://www.youtube.com/watch?v=yLdZCPmX-Bc)
# 特点
- 支持基于SAM的**交互式半自动标注**。
- 支持**手动标注**多边形。
- 支持标注**二次修改**。
@ -25,26 +27,32 @@ Demo Video[youtube](https://www.youtube.com/watch?v=yLdZCPmX-Bc)
- 更多功能详见[功能说明](./docs/功能说明.md)
# 安装
## 1. 源码运行
### (1) 创建虚拟环境
```shell
conda create -n ISAT_with_segment_anything python==3.8
conda activate ISAT_with_segment_anything
```
### (2) 安装ISAT_with_segment_anything
```shell
git clone https://github.com/yatengLG/ISAT_with_segment_anything.git
cd ISAT_with_segment_anything
pip install -r requirements.txt
```
### (3) 下载Segment anything预训练模型
下载预训练模型并将模型存放于ISAT_with_segment_anything/segment_any目录下
当前支持的模型有[SAM](https://github.com/facebookresearch/segment-anything)系列,[sam-hq](https://github.com/SysCV/sam-hq)系列,[MobileSAM](https://github.com/ChaoningZhang/MobileSAM)系列。
| 系列 | 预训练模型 | 显存占用 | 文件大小 |
|----|----|----|----|
| ---------- | ------------------------------------------------------------------------------------------ | -------- | -------- |
| SAM | [sam_vit_h_4b8939.pth](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth) | 7305M | 2.6G |
| | [sam_vit_l_0b3195.pth](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_l_0b3195.pth) | 5855M | 2.6G |
| | [sam_vit_b_01ec64.pth](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth) | 4149M | 375M |
@ -57,11 +65,13 @@ pip install -r requirements.txt
下载好模型后通过SAM-下拉列表选择要用的模型。切换模型需要一定时间切换h模型大概需要5秒左右视硬件情况而定。
### (4) 运行软件
```shell
python main.py
```
## 2. windows下exe运行
### (1) 下载打包好的exe文件
需下载三个.zip文件总体大小2.7G解压缩后4.9G。
@ -69,7 +79,7 @@ python main.py
打开ISAT_with_segment_anything文件夹双击main.exe运行。
| | 下载链接 |
|--------|-----------------------------------------------------------|
| -------- | ------------------------------------------------------------------ |
| 百度网盘 | 链接https://pan.baidu.com/s/1vD19PzvIT1QAJrAkSVFfhg 提取码ISAT |
### (2) 下载Segment anything预训练模型
@ -80,9 +90,25 @@ python main.py
下载地址同上[下载预训练模型](https://github.com/yatengLG/ISAT_with_segment_anything/#3-下载segment-anything预训练模型)
## 3. nuitka打包说明
经过在windows11上的测试合适的环境之一为
```
python=3.7.10
numpy=1.20.1
torch=1.10.0+cu102 或任意cpu版本的torch
```
其它库按需安装即可,未发现冲突情况
# 使用
软件具体功能可查看:[功能说明](./docs/功能说明.md)
## 1.标注
```text
1. 软件左侧选择类别(工具栏-文件-设置中,进行类别添加或修改)
2. 开始标注
@ -99,7 +125,9 @@ python main.py
3. 点击工具栏[标注完成]按钮完成标注快捷键E
4. 点击工具栏[保存]按钮快捷键S写入json文件。
```
## 2.修改
```text
1. 多边形修改
拖拽多边形顶点,修改多边形形状。
@ -111,7 +139,9 @@ python main.py
4. 删除目标
选定目标,点击工具栏[删除]按钮快捷键DEL删除选定目标。
```
## 3.查看
```text
1. 结果预览
点击工具栏[位图]按钮快捷键SPACE预览标注结果。
@ -125,9 +155,12 @@ python main.py
半自动标注时会调暗背景凸显mask。
通过工具栏[mask alpha]数值条调整背景与mask混合比例。
```
## 4.数据转换
本软件用json文件保存标注结果。
使用时可以手动解析json文件或转换为其他数据格式。
```text
软件内置了转换工具
1. ISAT转VOC
@ -141,6 +174,7 @@ python main.py
```
# 引用
```text
@misc{ISAT with segment anything,
title={{ISAT with segment anything}: Image segmentation annotation tool with segment anything},

BIN
icons/logo.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

2212
icons_rc.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,6 @@ from PyQt5 import QtWidgets
import os
import sys
os.environ['SAM_ANN_BASE_DIR'] = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(os.environ['SAM_ANN_BASE_DIR'], 'lib'))
from sam_ann import MainWindow

View File

@ -1,11 +1,8 @@
imgviz==1.2.6
mahotas==1.4.13
numpy==1.24.3
opencv_python_headless==4.5.3.56
opencv_python==4.5.3.56
Pillow==9.2.0
PyQt5==5.15.7
PyYAML==6.0
torch==1.8.1
torchvision==0.9.1
pycocotools
timm

View File

@ -20,6 +20,6 @@ label:
name: cake
- color: '#5c3566'
name: fence
language: en
language: zh
mask_alpha: 0.7
vertex_size: 2

View File

@ -130,7 +130,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.statusbar.showMessage("Segment anything only use the 3 dim with shape {} .".format(image_data.shape))
else:
self.statusbar.showMessage("Segment anything don't support the image with shape {} .".format(image_data.shape))
self.image_changed = False
self.show_image(self.current_index)
# if self.current_index is not None:
# self.image_changed = False
@ -360,6 +360,14 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
return
if not self.image_changed:
self.scene.cancel_draw()
self.actionSegment_anything.setEnabled(self.use_segment_anything)
self.actionPolygon.setEnabled(True)
self.actionSave.setEnabled(True)
self.actionBit_map.setEnabled(True)
self.actionBackspace.setEnabled(True)
self.actionFinish.setEnabled(True)
self.actionCancel.setEnabled(True)
self.actionVisible.setEnabled(True)
return
try:
self.scene.cancel_draw()