Skip to content

Commit 41060a9

Browse files
authored
upload initial code (#1)
1 parent 2c70bda commit 41060a9

Some content is hidden

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

56 files changed

+10489
-1
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# this drop notebooks from GitHub language stats
2+
*.ipynb linguist-vendored

.gitignore

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
*.pyc
2+
*.swp
3+
*.pkl
4+
*.pth
5+
result*
6+
weights*
7+
.vscode
8+
9+
# outputs
10+
outputs
11+
sliced_prediction_data
12+
13+
# mmdetection
14+
mmdetection/build
15+
mmdetection/demo
16+
mmdetection/experiments
17+
18+
# Byte-compiled / optimized / DLL files
19+
__pycache__/
20+
*.py[cod]
21+
*$py.class
22+
23+
# C extensions
24+
*.so
25+
26+
# Distribution / packaging
27+
.Python
28+
build/
29+
develop-eggs/
30+
dist/
31+
downloads/
32+
eggs/
33+
.eggs/
34+
lib/
35+
lib64/
36+
parts/
37+
sdist/
38+
var/
39+
wheels/
40+
pip-wheel-metadata/
41+
share/python-wheels/
42+
*.egg-info/
43+
.installed.cfg
44+
*.egg
45+
MANIFEST
46+
47+
# PyInstaller
48+
# Usually these files are written by a python script from a template
49+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
50+
*.manifest
51+
*.spec
52+
53+
# Installer logs
54+
pip-log.txt
55+
pip-delete-this-directory.txt
56+
57+
# Unit test / coverage reports
58+
htmlcov/
59+
.tox/
60+
.nox/
61+
.coverage
62+
.coverage.*
63+
.cache
64+
nosetests.xml
65+
coverage.xml
66+
*.cover
67+
*.py,cover
68+
.hypothesis/
69+
.pytest_cache/
70+
cover/
71+
72+
# Translations
73+
*.mo
74+
*.pot
75+
76+
# Django stuff:
77+
*.log
78+
local_settings.py
79+
db.sqlite3
80+
db.sqlite3-journal
81+
82+
# Flask stuff:
83+
instance/
84+
.webassets-cache
85+
86+
# Scrapy stuff:
87+
.scrapy
88+
89+
# Sphinx documentation
90+
docs/_build/
91+
92+
# PyBuilder
93+
.pybuilder/
94+
target/
95+
96+
# Jupyter Notebook
97+
.ipynb_checkpoints
98+
99+
# IPython
100+
profile_default/
101+
ipython_config.py
102+
103+
# pyenv
104+
# For a library or package, you might want to ignore these files since the code is
105+
# intended to run in multiple environments; otherwise, check them in:
106+
# .python-version
107+
108+
# pipenv
109+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
110+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
111+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
112+
# install all needed dependencies.
113+
#Pipfile.lock
114+
115+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
116+
__pypackages__/
117+
118+
# Celery stuff
119+
celerybeat-schedule
120+
celerybeat.pid
121+
122+
# SageMath parsed files
123+
*.sage.py
124+
125+
# Environments
126+
.env
127+
.venv
128+
env/
129+
venv/
130+
ENV/
131+
env.bak/
132+
venv.bak/
133+
134+
# Spyder project settings
135+
.spyderproject
136+
.spyproject
137+
138+
# Rope project settings
139+
.ropeproject
140+
141+
# mkdocs documentation
142+
/site
143+
144+
# mypy
145+
.mypy_cache/
146+
.dmypy.json
147+
dmypy.json
148+
149+
# Pyre type checker
150+
.pyre/
151+
152+
# pytype static type analyzer
153+
.pytype/
154+
155+
# Cython debug symbols
156+
cython_debug/
157+
158+
# Elastic Beanstalk Files
159+
.elasticbeanstalk/*
160+
!.elasticbeanstalk/*.cfg.yml
161+
!.elasticbeanstalk/*.global.yml

README.md

+90-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,91 @@
1-
# sahi
1+
# SAHI: Slicing Aided Hyper Inference
2+
23
A vision library for performing sliced inference on large images/small objects
4+
5+
<img width="700" alt="teaser" src="./demo/sliced_inference.gif">
6+
7+
## Overview
8+
9+
Object detection and instance segmentation are by far the most important fields of applications in Computer Vision. However, detection of small objects and inference on large images are still major issues in practical usage. Here comes the SAHI to help developers overcome these real-world problems.
10+
11+
## Getting started
12+
13+
### Blogpost
14+
15+
Check the [official SAHI blog post](https://medium.com/@fcakyon/sahi-a-vision-library-for-performing-sliced-inference-on-large-images-small-objects-c8b086af3b80).
16+
17+
18+
### Installation
19+
20+
- Install sahi using conda:
21+
22+
```console
23+
conda install -c obss sahi
24+
```
25+
26+
- Install sahi using pip:
27+
28+
```console
29+
pip install sahi
30+
```
31+
32+
- Install your desired version of pytorch and torchvision:
33+
```console
34+
pip install torch torchvision
35+
```
36+
37+
- Install your desired detection framework (such as mmdet):
38+
```console
39+
pip install mmdet
40+
```
41+
42+
## Usage
43+
44+
- Sliced inference:
45+
```python
46+
result = get_sliced_prediction(
47+
image,
48+
detection_model,
49+
slice_height = 256,
50+
slice_width = 256,
51+
overlap_height_ratio = 0.2,
52+
overlap_width_ratio = 0.2
53+
)
54+
55+
```
56+
Refer to [inference notebook](demo/inference.ipynb) for detailed usage.
57+
58+
- Slice an image:
59+
```python
60+
from sahi.slicing import slice_image
61+
62+
slice_image_result, num_total_invalid_segmentation = slice_image(
63+
image=image_path,
64+
output_file_name=output_file_name,
65+
output_dir=output_dir,
66+
slice_height=256,
67+
slice_width=256,
68+
overlap_height_ratio=0.2,
69+
overlap_width_ratio=0.2,
70+
)
71+
```
72+
73+
- Slice a coco formatted dataset:
74+
```python
75+
from sahi.slicing import slice_coco
76+
77+
coco_dict, coco_path = slice_coco(
78+
coco_annotation_file_path=coco_annotation_file_path,
79+
image_dir=image_dir,
80+
slice_height=256,
81+
slice_width=256,
82+
overlap_height_ratio=0.2,
83+
overlap_width_ratio=0.2,
84+
)
85+
```
86+
87+
## Adding new detection framework support
88+
89+
sahi library currently only supports [MMDetection models](https://github.com/open-mmlab/mmdetection/blob/master/docs/model_zoo.md). However it is easy to add new frameworks.
90+
91+
All you need to do is, creating a new class in [model.py](sahi/model.py) that implements [DetectionModel class](https://github.com/obss/sahi/blob/651f8e6cdb20467815748764bb198dd50241ab2b/sahi/model.py#L10). You can take the [MMDetection wrapper](https://github.com/obss/sahi/blob/651f8e6cdb20467815748764bb198dd50241ab2b/sahi/model.py#L164) as a reference.

demo/image_dir/small-vehicles1.jpeg

316 KB
Loading

demo/inference.ipynb

+490
Large diffs are not rendered by default.

demo/sliced_inference.gif

1.98 MB
Loading

requirements.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
opencv-python>=4.2.0.32
2+
shapely>=1.7.0
3+
tqdm>=4.48.2
4+
imantics>=0.1.12
5+
scikit-image>=0.14.2

sahi/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.0"

0 commit comments

Comments
 (0)