Skip to content

Commit 7bb1a6e

Browse files
authored
Merge pull request CASIA-IVA-Lab#231 from CASIA-IVA-Lab/dev
Optimized the jagged edges issue in segmentation.
2 parents 02c9dfb + 1437cdb commit 7bb1a6e

File tree

166 files changed

+30588
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+30588
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cd FastSAM
4444
pip install -r requirements.txt
4545
```
4646

47-
Install CLIP:
47+
Install CLIP(Required if the text prompt is being tested.):
4848

4949
```shell
5050
pip install git+https://github.com/openai/CLIP.git

fastsam/decoder.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from .model import FastSAM
22
import numpy as np
33
from PIL import Image
4-
import clip
54
from typing import Optional, List, Tuple, Union
65

76

fastsam/prompt.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
from .utils import image_to_np_ndarray
88
from PIL import Image
99

10-
try:
11-
import clip # for linear_assignment
12-
13-
except (ImportError, AssertionError, AttributeError):
14-
from ultralytics.yolo.utils.checks import check_requirements
15-
16-
check_requirements('git+https://github.com/openai/CLIP.git') # required before installing lap from source
17-
import clip
18-
1910

2011
class FastSAMPrompt:
2112

@@ -340,6 +331,16 @@ def fast_show_mask_gpu(
340331
@torch.no_grad()
341332
def retrieve(self, model, preprocess, elements, search_text: str, device) -> int:
342333
preprocessed_images = [preprocess(image).to(device) for image in elements]
334+
try:
335+
import clip # for linear_assignment
336+
337+
except (ImportError, AssertionError, AttributeError):
338+
from ultralytics.yolo.utils.checks import check_requirements
339+
340+
check_requirements('git+https://github.com/openai/CLIP.git') # required before installing lap from source
341+
import clip
342+
343+
343344
tokenized_text = clip.tokenize([search_text]).to(device)
344345
stacked_images = torch.stack(preprocessed_images)
345346
image_features = model.encode_image(stacked_images)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ seaborn>=0.11.0
1515
gradio==3.35.2
1616

1717
# Ultralytics-----------------------------------
18-
ultralytics == 8.0.120
18+
# ultralytics == 8.0.120
1919

ultralytics/.pre-commit-config.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Ultralytics YOLO 🚀, AGPL-3.0 license
2+
# Pre-commit hooks. For more information see https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md
3+
4+
exclude: 'docs/'
5+
# Define bot property if installed via https://github.com/marketplace/pre-commit-ci
6+
ci:
7+
autofix_prs: true
8+
autoupdate_commit_msg: '[pre-commit.ci] pre-commit suggestions'
9+
autoupdate_schedule: monthly
10+
# submodules: true
11+
12+
repos:
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v4.4.0
15+
hooks:
16+
- id: end-of-file-fixer
17+
- id: trailing-whitespace
18+
- id: check-case-conflict
19+
# - id: check-yaml
20+
- id: check-docstring-first
21+
- id: double-quote-string-fixer
22+
- id: detect-private-key
23+
24+
- repo: https://github.com/asottile/pyupgrade
25+
rev: v3.4.0
26+
hooks:
27+
- id: pyupgrade
28+
name: Upgrade code
29+
30+
- repo: https://github.com/PyCQA/isort
31+
rev: 5.12.0
32+
hooks:
33+
- id: isort
34+
name: Sort imports
35+
36+
- repo: https://github.com/google/yapf
37+
rev: v0.33.0
38+
hooks:
39+
- id: yapf
40+
name: YAPF formatting
41+
42+
- repo: https://github.com/executablebooks/mdformat
43+
rev: 0.7.16
44+
hooks:
45+
- id: mdformat
46+
name: MD formatting
47+
additional_dependencies:
48+
- mdformat-gfm
49+
- mdformat-black
50+
# exclude: "README.md|README.zh-CN.md|CONTRIBUTING.md"
51+
52+
- repo: https://github.com/PyCQA/flake8
53+
rev: 6.0.0
54+
hooks:
55+
- id: flake8
56+
name: PEP8
57+
58+
- repo: https://github.com/codespell-project/codespell
59+
rev: v2.2.4
60+
hooks:
61+
- id: codespell
62+
args:
63+
- --ignore-words-list=crate,nd,strack,dota
64+
65+
# - repo: https://github.com/asottile/yesqa
66+
# rev: v1.4.0
67+
# hooks:
68+
# - id: yesqa
69+
70+
# - repo: https://github.com/asottile/dead
71+
# rev: v1.5.0
72+
# hooks:
73+
# - id: dead

ultralytics/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Ultralytics YOLO 🚀, AGPL-3.0 license
2+
3+
__version__ = '8.0.120'
4+
5+
from ultralytics.hub import start
6+
from ultralytics.vit.rtdetr import RTDETR
7+
from ultralytics.vit.sam import SAM
8+
from ultralytics.yolo.engine.model import YOLO
9+
from ultralytics.yolo.nas import NAS
10+
from ultralytics.yolo.utils.checks import check_yolo as checks
11+
12+
__all__ = '__version__', 'YOLO', 'NAS', 'SAM', 'RTDETR', 'checks', 'start' # allow simpler import

ultralytics/assets/bus.jpg

134 KB
Loading

ultralytics/assets/zidane.jpg

49.2 KB
Loading

ultralytics/datasets/Argoverse.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Ultralytics YOLO 🚀, AGPL-3.0 license
2+
# Argoverse-HD dataset (ring-front-center camera) http://www.cs.cmu.edu/~mengtial/proj/streaming/ by Argo AI
3+
# Example usage: yolo train data=Argoverse.yaml
4+
# parent
5+
# ├── ultralytics
6+
# └── datasets
7+
# └── Argoverse ← downloads here (31.3 GB)
8+
9+
10+
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
11+
path: ../datasets/Argoverse # dataset root dir
12+
train: Argoverse-1.1/images/train/ # train images (relative to 'path') 39384 images
13+
val: Argoverse-1.1/images/val/ # val images (relative to 'path') 15062 images
14+
test: Argoverse-1.1/images/test/ # test images (optional) https://eval.ai/web/challenges/challenge-page/800/overview
15+
16+
# Classes
17+
names:
18+
0: person
19+
1: bicycle
20+
2: car
21+
3: motorcycle
22+
4: bus
23+
5: truck
24+
6: traffic_light
25+
7: stop_sign
26+
27+
28+
# Download script/URL (optional) ---------------------------------------------------------------------------------------
29+
download: |
30+
import json
31+
from tqdm import tqdm
32+
from ultralytics.yolo.utils.downloads import download
33+
from pathlib import Path
34+
35+
def argoverse2yolo(set):
36+
labels = {}
37+
a = json.load(open(set, "rb"))
38+
for annot in tqdm(a['annotations'], desc=f"Converting {set} to YOLOv5 format..."):
39+
img_id = annot['image_id']
40+
img_name = a['images'][img_id]['name']
41+
img_label_name = f'{img_name[:-3]}txt'
42+
43+
cls = annot['category_id'] # instance class id
44+
x_center, y_center, width, height = annot['bbox']
45+
x_center = (x_center + width / 2) / 1920.0 # offset and scale
46+
y_center = (y_center + height / 2) / 1200.0 # offset and scale
47+
width /= 1920.0 # scale
48+
height /= 1200.0 # scale
49+
50+
img_dir = set.parents[2] / 'Argoverse-1.1' / 'labels' / a['seq_dirs'][a['images'][annot['image_id']]['sid']]
51+
if not img_dir.exists():
52+
img_dir.mkdir(parents=True, exist_ok=True)
53+
54+
k = str(img_dir / img_label_name)
55+
if k not in labels:
56+
labels[k] = []
57+
labels[k].append(f"{cls} {x_center} {y_center} {width} {height}\n")
58+
59+
for k in labels:
60+
with open(k, "w") as f:
61+
f.writelines(labels[k])
62+
63+
64+
# Download
65+
dir = Path(yaml['path']) # dataset root dir
66+
urls = ['https://argoverse-hd.s3.us-east-2.amazonaws.com/Argoverse-HD-Full.zip']
67+
download(urls, dir=dir)
68+
69+
# Convert
70+
annotations_dir = 'Argoverse-HD/annotations/'
71+
(dir / 'Argoverse-1.1' / 'tracking').rename(dir / 'Argoverse-1.1' / 'images') # rename 'tracking' to 'images'
72+
for d in "train.json", "val.json":
73+
argoverse2yolo(dir / annotations_dir / d) # convert VisDrone annotations to YOLO labels
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Ultralytics YOLO 🚀, AGPL-3.0 license
2+
# Global Wheat 2020 dataset http://www.global-wheat.com/ by University of Saskatchewan
3+
# Example usage: yolo train data=GlobalWheat2020.yaml
4+
# parent
5+
# ├── ultralytics
6+
# └── datasets
7+
# └── GlobalWheat2020 ← downloads here (7.0 GB)
8+
9+
10+
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
11+
path: ../datasets/GlobalWheat2020 # dataset root dir
12+
train: # train images (relative to 'path') 3422 images
13+
- images/arvalis_1
14+
- images/arvalis_2
15+
- images/arvalis_3
16+
- images/ethz_1
17+
- images/rres_1
18+
- images/inrae_1
19+
- images/usask_1
20+
val: # val images (relative to 'path') 748 images (WARNING: train set contains ethz_1)
21+
- images/ethz_1
22+
test: # test images (optional) 1276 images
23+
- images/utokyo_1
24+
- images/utokyo_2
25+
- images/nau_1
26+
- images/uq_1
27+
28+
# Classes
29+
names:
30+
0: wheat_head
31+
32+
33+
# Download script/URL (optional) ---------------------------------------------------------------------------------------
34+
download: |
35+
from ultralytics.yolo.utils.downloads import download
36+
from pathlib import Path
37+
38+
# Download
39+
dir = Path(yaml['path']) # dataset root dir
40+
urls = ['https://zenodo.org/record/4298502/files/global-wheat-codalab-official.zip',
41+
'https://github.com/ultralytics/yolov5/releases/download/v1.0/GlobalWheat2020_labels.zip']
42+
download(urls, dir=dir)
43+
44+
# Make Directories
45+
for p in 'annotations', 'images', 'labels':
46+
(dir / p).mkdir(parents=True, exist_ok=True)
47+
48+
# Move
49+
for p in 'arvalis_1', 'arvalis_2', 'arvalis_3', 'ethz_1', 'rres_1', 'inrae_1', 'usask_1', \
50+
'utokyo_1', 'utokyo_2', 'nau_1', 'uq_1':
51+
(dir / 'global-wheat-codalab-official' / p).rename(dir / 'images' / p) # move to /images
52+
f = (dir / 'global-wheat-codalab-official' / p).with_suffix('.json') # json file
53+
if f.exists():
54+
f.rename((dir / 'annotations' / p).with_suffix('.json')) # move to /annotations

0 commit comments

Comments
 (0)