Spaces:
Running
Running
Darius Morawiec
commited on
Commit
·
d9de329
1
Parent(s):
f0e65cc
Add initial version of app
Browse files- .gitignore +373 -0
- .python-version +1 -0
- README.md +3 -2
- app.py +252 -0
- pyproject.toml +9 -0
- requirements.txt +3 -0
- uv.lock +0 -0
.gitignore
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.gradio
|
| 2 |
+
*.pth
|
| 3 |
+
*.csv
|
| 4 |
+
|
| 5 |
+
# Created by https://www.toptal.com/developers/gitignore/api/macos,dotenv,python,windows,intellij,visualstudiocode
|
| 6 |
+
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,dotenv,python,windows,intellij,visualstudiocode
|
| 7 |
+
|
| 8 |
+
### dotenv ###
|
| 9 |
+
.env
|
| 10 |
+
|
| 11 |
+
### Intellij ###
|
| 12 |
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
| 13 |
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
| 14 |
+
|
| 15 |
+
# User-specific stuff
|
| 16 |
+
.idea/**/workspace.xml
|
| 17 |
+
.idea/**/tasks.xml
|
| 18 |
+
.idea/**/usage.statistics.xml
|
| 19 |
+
.idea/**/dictionaries
|
| 20 |
+
.idea/**/shelf
|
| 21 |
+
|
| 22 |
+
# AWS User-specific
|
| 23 |
+
.idea/**/aws.xml
|
| 24 |
+
|
| 25 |
+
# Generated files
|
| 26 |
+
.idea/**/contentModel.xml
|
| 27 |
+
|
| 28 |
+
# Sensitive or high-churn files
|
| 29 |
+
.idea/**/dataSources/
|
| 30 |
+
.idea/**/dataSources.ids
|
| 31 |
+
.idea/**/dataSources.local.xml
|
| 32 |
+
.idea/**/sqlDataSources.xml
|
| 33 |
+
.idea/**/dynamic.xml
|
| 34 |
+
.idea/**/uiDesigner.xml
|
| 35 |
+
.idea/**/dbnavigator.xml
|
| 36 |
+
|
| 37 |
+
# Gradle
|
| 38 |
+
.idea/**/gradle.xml
|
| 39 |
+
.idea/**/libraries
|
| 40 |
+
|
| 41 |
+
# Gradle and Maven with auto-import
|
| 42 |
+
# When using Gradle or Maven with auto-import, you should exclude module files,
|
| 43 |
+
# since they will be recreated, and may cause churn. Uncomment if using
|
| 44 |
+
# auto-import.
|
| 45 |
+
# .idea/artifacts
|
| 46 |
+
# .idea/compiler.xml
|
| 47 |
+
# .idea/jarRepositories.xml
|
| 48 |
+
# .idea/modules.xml
|
| 49 |
+
# .idea/*.iml
|
| 50 |
+
# .idea/modules
|
| 51 |
+
# *.iml
|
| 52 |
+
# *.ipr
|
| 53 |
+
|
| 54 |
+
# CMake
|
| 55 |
+
cmake-build-*/
|
| 56 |
+
|
| 57 |
+
# Mongo Explorer plugin
|
| 58 |
+
.idea/**/mongoSettings.xml
|
| 59 |
+
|
| 60 |
+
# File-based project format
|
| 61 |
+
*.iws
|
| 62 |
+
|
| 63 |
+
# IntelliJ
|
| 64 |
+
out/
|
| 65 |
+
|
| 66 |
+
# mpeltonen/sbt-idea plugin
|
| 67 |
+
.idea_modules/
|
| 68 |
+
|
| 69 |
+
# JIRA plugin
|
| 70 |
+
atlassian-ide-plugin.xml
|
| 71 |
+
|
| 72 |
+
# Cursive Clojure plugin
|
| 73 |
+
.idea/replstate.xml
|
| 74 |
+
|
| 75 |
+
# SonarLint plugin
|
| 76 |
+
.idea/sonarlint/
|
| 77 |
+
|
| 78 |
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
| 79 |
+
com_crashlytics_export_strings.xml
|
| 80 |
+
crashlytics.properties
|
| 81 |
+
crashlytics-build.properties
|
| 82 |
+
fabric.properties
|
| 83 |
+
|
| 84 |
+
# Editor-based Rest Client
|
| 85 |
+
.idea/httpRequests
|
| 86 |
+
|
| 87 |
+
# Android studio 3.1+ serialized cache file
|
| 88 |
+
.idea/caches/build_file_checksums.ser
|
| 89 |
+
|
| 90 |
+
### Intellij Patch ###
|
| 91 |
+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
| 92 |
+
|
| 93 |
+
# *.iml
|
| 94 |
+
# modules.xml
|
| 95 |
+
# .idea/misc.xml
|
| 96 |
+
# *.ipr
|
| 97 |
+
|
| 98 |
+
# Sonarlint plugin
|
| 99 |
+
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
| 100 |
+
.idea/**/sonarlint/
|
| 101 |
+
|
| 102 |
+
# SonarQube Plugin
|
| 103 |
+
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
| 104 |
+
.idea/**/sonarIssues.xml
|
| 105 |
+
|
| 106 |
+
# Markdown Navigator plugin
|
| 107 |
+
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
| 108 |
+
.idea/**/markdown-navigator.xml
|
| 109 |
+
.idea/**/markdown-navigator-enh.xml
|
| 110 |
+
.idea/**/markdown-navigator/
|
| 111 |
+
|
| 112 |
+
# Cache file creation bug
|
| 113 |
+
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
| 114 |
+
.idea/$CACHE_FILE$
|
| 115 |
+
|
| 116 |
+
# CodeStream plugin
|
| 117 |
+
# https://plugins.jetbrains.com/plugin/12206-codestream
|
| 118 |
+
.idea/codestream.xml
|
| 119 |
+
|
| 120 |
+
# Azure Toolkit for IntelliJ plugin
|
| 121 |
+
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
|
| 122 |
+
.idea/**/azureSettings.xml
|
| 123 |
+
|
| 124 |
+
### macOS ###
|
| 125 |
+
# General
|
| 126 |
+
.DS_Store
|
| 127 |
+
.AppleDouble
|
| 128 |
+
.LSOverride
|
| 129 |
+
|
| 130 |
+
# Icon must end with two \r
|
| 131 |
+
Icon
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
# Thumbnails
|
| 135 |
+
._*
|
| 136 |
+
|
| 137 |
+
# Files that might appear in the root of a volume
|
| 138 |
+
.DocumentRevisions-V100
|
| 139 |
+
.fseventsd
|
| 140 |
+
.Spotlight-V100
|
| 141 |
+
.TemporaryItems
|
| 142 |
+
.Trashes
|
| 143 |
+
.VolumeIcon.icns
|
| 144 |
+
.com.apple.timemachine.donotpresent
|
| 145 |
+
|
| 146 |
+
# Directories potentially created on remote AFP share
|
| 147 |
+
.AppleDB
|
| 148 |
+
.AppleDesktop
|
| 149 |
+
Network Trash Folder
|
| 150 |
+
Temporary Items
|
| 151 |
+
.apdisk
|
| 152 |
+
|
| 153 |
+
### macOS Patch ###
|
| 154 |
+
# iCloud generated files
|
| 155 |
+
*.icloud
|
| 156 |
+
|
| 157 |
+
### Python ###
|
| 158 |
+
# Byte-compiled / optimized / DLL files
|
| 159 |
+
__pycache__/
|
| 160 |
+
*.py[cod]
|
| 161 |
+
*$py.class
|
| 162 |
+
|
| 163 |
+
# C extensions
|
| 164 |
+
*.so
|
| 165 |
+
|
| 166 |
+
# Distribution / packaging
|
| 167 |
+
.Python
|
| 168 |
+
build/
|
| 169 |
+
develop-eggs/
|
| 170 |
+
dist/
|
| 171 |
+
downloads/
|
| 172 |
+
eggs/
|
| 173 |
+
.eggs/
|
| 174 |
+
lib/
|
| 175 |
+
lib64/
|
| 176 |
+
parts/
|
| 177 |
+
sdist/
|
| 178 |
+
var/
|
| 179 |
+
wheels/
|
| 180 |
+
share/python-wheels/
|
| 181 |
+
*.egg-info/
|
| 182 |
+
.installed.cfg
|
| 183 |
+
*.egg
|
| 184 |
+
MANIFEST
|
| 185 |
+
|
| 186 |
+
# PyInstaller
|
| 187 |
+
# Usually these files are written by a python script from a template
|
| 188 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 189 |
+
*.manifest
|
| 190 |
+
*.spec
|
| 191 |
+
|
| 192 |
+
# Installer logs
|
| 193 |
+
pip-log.txt
|
| 194 |
+
pip-delete-this-directory.txt
|
| 195 |
+
|
| 196 |
+
# Unit test / coverage reports
|
| 197 |
+
htmlcov/
|
| 198 |
+
.tox/
|
| 199 |
+
.nox/
|
| 200 |
+
.coverage
|
| 201 |
+
.coverage.*
|
| 202 |
+
.cache
|
| 203 |
+
nosetests.xml
|
| 204 |
+
coverage.xml
|
| 205 |
+
*.cover
|
| 206 |
+
*.py,cover
|
| 207 |
+
.hypothesis/
|
| 208 |
+
.pytest_cache/
|
| 209 |
+
cover/
|
| 210 |
+
|
| 211 |
+
# Translations
|
| 212 |
+
*.mo
|
| 213 |
+
*.pot
|
| 214 |
+
|
| 215 |
+
# Django stuff:
|
| 216 |
+
*.log
|
| 217 |
+
local_settings.py
|
| 218 |
+
db.sqlite3
|
| 219 |
+
db.sqlite3-journal
|
| 220 |
+
|
| 221 |
+
# Flask stuff:
|
| 222 |
+
instance/
|
| 223 |
+
.webassets-cache
|
| 224 |
+
|
| 225 |
+
# Scrapy stuff:
|
| 226 |
+
.scrapy
|
| 227 |
+
|
| 228 |
+
# Sphinx documentation
|
| 229 |
+
docs/_build/
|
| 230 |
+
|
| 231 |
+
# PyBuilder
|
| 232 |
+
.pybuilder/
|
| 233 |
+
target/
|
| 234 |
+
|
| 235 |
+
# Jupyter Notebook
|
| 236 |
+
.ipynb_checkpoints
|
| 237 |
+
|
| 238 |
+
# IPython
|
| 239 |
+
profile_default/
|
| 240 |
+
ipython_config.py
|
| 241 |
+
|
| 242 |
+
# pyenv
|
| 243 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 244 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 245 |
+
# .python-version
|
| 246 |
+
|
| 247 |
+
# pipenv
|
| 248 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 249 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 250 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 251 |
+
# install all needed dependencies.
|
| 252 |
+
#Pipfile.lock
|
| 253 |
+
|
| 254 |
+
# poetry
|
| 255 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 256 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 257 |
+
# commonly ignored for libraries.
|
| 258 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 259 |
+
#poetry.lock
|
| 260 |
+
|
| 261 |
+
# pdm
|
| 262 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 263 |
+
#pdm.lock
|
| 264 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 265 |
+
# in version control.
|
| 266 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 267 |
+
.pdm.toml
|
| 268 |
+
|
| 269 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 270 |
+
__pypackages__/
|
| 271 |
+
|
| 272 |
+
# Celery stuff
|
| 273 |
+
celerybeat-schedule
|
| 274 |
+
celerybeat.pid
|
| 275 |
+
|
| 276 |
+
# SageMath parsed files
|
| 277 |
+
*.sage.py
|
| 278 |
+
|
| 279 |
+
# Environments
|
| 280 |
+
.venv
|
| 281 |
+
env/
|
| 282 |
+
venv/
|
| 283 |
+
ENV/
|
| 284 |
+
env.bak/
|
| 285 |
+
venv.bak/
|
| 286 |
+
|
| 287 |
+
# Spyder project settings
|
| 288 |
+
.spyderproject
|
| 289 |
+
.spyproject
|
| 290 |
+
|
| 291 |
+
# Rope project settings
|
| 292 |
+
.ropeproject
|
| 293 |
+
|
| 294 |
+
# mkdocs documentation
|
| 295 |
+
/site
|
| 296 |
+
|
| 297 |
+
# mypy
|
| 298 |
+
.mypy_cache/
|
| 299 |
+
.dmypy.json
|
| 300 |
+
dmypy.json
|
| 301 |
+
|
| 302 |
+
# Pyre type checker
|
| 303 |
+
.pyre/
|
| 304 |
+
|
| 305 |
+
# pytype static type analyzer
|
| 306 |
+
.pytype/
|
| 307 |
+
|
| 308 |
+
# Cython debug symbols
|
| 309 |
+
cython_debug/
|
| 310 |
+
|
| 311 |
+
# PyCharm
|
| 312 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 313 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 314 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 315 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 316 |
+
#.idea/
|
| 317 |
+
|
| 318 |
+
### Python Patch ###
|
| 319 |
+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
| 320 |
+
poetry.toml
|
| 321 |
+
|
| 322 |
+
# ruff
|
| 323 |
+
.ruff_cache/
|
| 324 |
+
|
| 325 |
+
# LSP config files
|
| 326 |
+
pyrightconfig.json
|
| 327 |
+
|
| 328 |
+
### VisualStudioCode ###
|
| 329 |
+
.vscode/*
|
| 330 |
+
!.vscode/settings.json
|
| 331 |
+
!.vscode/tasks.json
|
| 332 |
+
!.vscode/launch.json
|
| 333 |
+
!.vscode/extensions.json
|
| 334 |
+
!.vscode/*.code-snippets
|
| 335 |
+
|
| 336 |
+
# Local History for Visual Studio Code
|
| 337 |
+
.history/
|
| 338 |
+
|
| 339 |
+
# Built Visual Studio Code Extensions
|
| 340 |
+
*.vsix
|
| 341 |
+
|
| 342 |
+
### VisualStudioCode Patch ###
|
| 343 |
+
# Ignore all local history of files
|
| 344 |
+
.history
|
| 345 |
+
.ionide
|
| 346 |
+
|
| 347 |
+
### Windows ###
|
| 348 |
+
# Windows thumbnail cache files
|
| 349 |
+
Thumbs.db
|
| 350 |
+
Thumbs.db:encryptable
|
| 351 |
+
ehthumbs.db
|
| 352 |
+
ehthumbs_vista.db
|
| 353 |
+
|
| 354 |
+
# Dump file
|
| 355 |
+
*.stackdump
|
| 356 |
+
|
| 357 |
+
# Folder config file
|
| 358 |
+
[Dd]esktop.ini
|
| 359 |
+
|
| 360 |
+
# Recycle Bin used on file shares
|
| 361 |
+
$RECYCLE.BIN/
|
| 362 |
+
|
| 363 |
+
# Windows Installer files
|
| 364 |
+
*.cab
|
| 365 |
+
*.msi
|
| 366 |
+
*.msix
|
| 367 |
+
*.msm
|
| 368 |
+
*.msp
|
| 369 |
+
|
| 370 |
+
# Windows shortcuts
|
| 371 |
+
*.lnk
|
| 372 |
+
|
| 373 |
+
# End of https://www.toptal.com/developers/gitignore/api/macos,dotenv,python,windows,intellij,visualstudiocode
|
.python-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
3.10
|
README.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
---
|
| 2 |
title: RF-DETR SAHI
|
| 3 |
emoji: ⚡
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.35.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
|
|
|
| 1 |
---
|
| 2 |
title: RF-DETR SAHI
|
| 3 |
emoji: ⚡
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.35.0
|
| 8 |
+
python_version: 3.10
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
license: apache-2.0
|
app.py
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from typing import Any
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import PIL
|
| 6 |
+
from rfdetr import RFDETRBase, RFDETRLarge
|
| 7 |
+
from rfdetr.detr import RFDETR
|
| 8 |
+
from rfdetr.util.coco_classes import COCO_CLASSES
|
| 9 |
+
from sahi import AutoDetectionModel
|
| 10 |
+
from sahi.predict import get_prediction, get_sliced_prediction
|
| 11 |
+
from sahi.utils.file import download_from_url
|
| 12 |
+
|
| 13 |
+
OUT_DIR = Path(__file__).parent / "out"
|
| 14 |
+
OUT_DIR.mkdir(parents=True, exist_ok=True)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
MARKDOWN = """
|
| 18 |
+
# RF-DETR + SAHI 🔥
|
| 19 |
+
|
| 20 |
+
This demo shows how to use [RF-DETR](https://github.com/roboflow/rf-detr) ([Apache-2.0](https://github.com/roboflow/rf-detr/blob/develop/LICENSE)) with [SAHI](https://github.com/obss/sahi) ([MIT](https://github.com/obss/sahi/blob/main/LICENSE)) to run predictions on large images.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
IMAGE_PROCESSING_EXAMPLES = [
|
| 24 |
+
[
|
| 25 |
+
"https://raw.githubusercontent.com/obss/sahi/main/demo/demo_data/small-vehicles1.jpeg",
|
| 26 |
+
"large",
|
| 27 |
+
560,
|
| 28 |
+
0.8,
|
| 29 |
+
224,
|
| 30 |
+
224,
|
| 31 |
+
0.2,
|
| 32 |
+
0.2,
|
| 33 |
+
],
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def load_model(checkpoint: str, resolution: int) -> RFDETR:
|
| 38 |
+
if checkpoint == "base":
|
| 39 |
+
return RFDETRBase(resolution=resolution)
|
| 40 |
+
elif checkpoint == "large":
|
| 41 |
+
return RFDETRLarge(resolution=resolution)
|
| 42 |
+
raise TypeError("checkpoint must be a base or large")
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def extend_model(
|
| 46 |
+
model: Any,
|
| 47 |
+
confidence_threshold: float,
|
| 48 |
+
category_mapping: dict,
|
| 49 |
+
):
|
| 50 |
+
model = AutoDetectionModel.from_pretrained(
|
| 51 |
+
model_type="roboflow",
|
| 52 |
+
model=model,
|
| 53 |
+
confidence_threshold=confidence_threshold,
|
| 54 |
+
category_mapping=category_mapping,
|
| 55 |
+
device="cpu",
|
| 56 |
+
)
|
| 57 |
+
return model
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def download_image(
|
| 61 |
+
image_url: str,
|
| 62 |
+
download_dir: Path | str | None = None,
|
| 63 |
+
) -> Path:
|
| 64 |
+
image_filename = image_url.split("/")[-1]
|
| 65 |
+
|
| 66 |
+
if not download_dir:
|
| 67 |
+
download_dir = OUT_DIR
|
| 68 |
+
|
| 69 |
+
if isinstance(download_dir, str):
|
| 70 |
+
download_dir = Path(download_dir)
|
| 71 |
+
|
| 72 |
+
download_dir.mkdir(parents=True, exist_ok=True)
|
| 73 |
+
download_path = Path(download_dir) / image_filename
|
| 74 |
+
download_path = download_path.resolve()
|
| 75 |
+
|
| 76 |
+
download_from_url(image_url, str(download_path))
|
| 77 |
+
|
| 78 |
+
return download_path
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def run_predictions(
|
| 82 |
+
image_processing_input_image: PIL.Image.Image,
|
| 83 |
+
image_processing_checkpoint_dropdown: str,
|
| 84 |
+
image_processing_resolution_slider: int,
|
| 85 |
+
image_processing_confidence_slider: float,
|
| 86 |
+
slice_height: int,
|
| 87 |
+
slice_width: int,
|
| 88 |
+
overlap_height_ratio: float,
|
| 89 |
+
overlap_width_ratio: float,
|
| 90 |
+
):
|
| 91 |
+
image_path = OUT_DIR / "input_image.jpg"
|
| 92 |
+
image_processing_input_image = image_processing_input_image.convert("RGB")
|
| 93 |
+
image_processing_input_image.save(str(image_path))
|
| 94 |
+
|
| 95 |
+
# Load model:
|
| 96 |
+
original_model = load_model(
|
| 97 |
+
checkpoint=image_processing_checkpoint_dropdown,
|
| 98 |
+
resolution=image_processing_resolution_slider,
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
# Extend model with SAHI:
|
| 102 |
+
model = extend_model(
|
| 103 |
+
model=original_model,
|
| 104 |
+
confidence_threshold=image_processing_confidence_slider,
|
| 105 |
+
category_mapping=COCO_CLASSES,
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
# Run original model prediction
|
| 109 |
+
prediction = get_prediction(
|
| 110 |
+
str(image_path),
|
| 111 |
+
model,
|
| 112 |
+
)
|
| 113 |
+
original_filename = f"{image_path.stem}_prediction"
|
| 114 |
+
prediction.export_visuals(
|
| 115 |
+
export_dir=str(OUT_DIR),
|
| 116 |
+
file_name=original_filename,
|
| 117 |
+
)
|
| 118 |
+
original_path = OUT_DIR / f"{original_filename}.png"
|
| 119 |
+
|
| 120 |
+
# Run sliced model prediction
|
| 121 |
+
prediction_sliced = get_sliced_prediction(
|
| 122 |
+
str(image_path),
|
| 123 |
+
model,
|
| 124 |
+
slice_width=slice_width,
|
| 125 |
+
slice_height=slice_height,
|
| 126 |
+
overlap_width_ratio=overlap_width_ratio,
|
| 127 |
+
overlap_height_ratio=overlap_height_ratio,
|
| 128 |
+
postprocess_match_threshold=image_processing_confidence_slider,
|
| 129 |
+
)
|
| 130 |
+
scliced_filename = f"{image_path.stem}_sliced_prediction"
|
| 131 |
+
prediction_sliced.export_visuals(
|
| 132 |
+
export_dir=str(OUT_DIR),
|
| 133 |
+
file_name=scliced_filename,
|
| 134 |
+
)
|
| 135 |
+
sliced_path = OUT_DIR / f"{scliced_filename}.png"
|
| 136 |
+
|
| 137 |
+
return original_path, sliced_path
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
with gr.Blocks(delete_cache=(10, 10)) as demo:
|
| 141 |
+
gr.Markdown(MARKDOWN)
|
| 142 |
+
|
| 143 |
+
with gr.Row():
|
| 144 |
+
image_processing_input_image = gr.Image(
|
| 145 |
+
label="Original Image",
|
| 146 |
+
image_mode="RGB",
|
| 147 |
+
type="pil",
|
| 148 |
+
height=600,
|
| 149 |
+
)
|
| 150 |
+
image_processing_output_image = gr.ImageSlider(
|
| 151 |
+
label="Original vs Sliced Prediction",
|
| 152 |
+
image_mode="RGB",
|
| 153 |
+
type="filepath",
|
| 154 |
+
height=600,
|
| 155 |
+
)
|
| 156 |
+
with gr.Row():
|
| 157 |
+
with gr.Column():
|
| 158 |
+
gr.Markdown("### RF-DETR Configuration")
|
| 159 |
+
image_processing_confidence_slider = gr.Slider(
|
| 160 |
+
label="Confidence",
|
| 161 |
+
minimum=0.0,
|
| 162 |
+
maximum=1.0,
|
| 163 |
+
step=0.05,
|
| 164 |
+
value=0.5,
|
| 165 |
+
)
|
| 166 |
+
image_processing_resolution_slider = gr.Slider(
|
| 167 |
+
label="Inference Resolution",
|
| 168 |
+
minimum=560,
|
| 169 |
+
maximum=1120,
|
| 170 |
+
step=56,
|
| 171 |
+
value=728,
|
| 172 |
+
)
|
| 173 |
+
image_processing_checkpoint_dropdown = gr.Dropdown(
|
| 174 |
+
label="Model Size",
|
| 175 |
+
choices=["base", "large"],
|
| 176 |
+
value="base",
|
| 177 |
+
)
|
| 178 |
+
with gr.Column():
|
| 179 |
+
gr.Markdown("### SAHI Configuration")
|
| 180 |
+
slice_width = gr.Slider(
|
| 181 |
+
label="Slice Width",
|
| 182 |
+
minimum=100,
|
| 183 |
+
maximum=500,
|
| 184 |
+
step=1,
|
| 185 |
+
value=224,
|
| 186 |
+
)
|
| 187 |
+
slice_height = gr.Slider(
|
| 188 |
+
label="Slice Height",
|
| 189 |
+
minimum=100,
|
| 190 |
+
maximum=500,
|
| 191 |
+
step=1,
|
| 192 |
+
value=224,
|
| 193 |
+
)
|
| 194 |
+
overlap_width_ratio = gr.Slider(
|
| 195 |
+
label="Overlap Width Ratio",
|
| 196 |
+
minimum=0.0,
|
| 197 |
+
maximum=1.0,
|
| 198 |
+
step=0.05,
|
| 199 |
+
value=0.2,
|
| 200 |
+
)
|
| 201 |
+
overlap_height_ratio = gr.Slider(
|
| 202 |
+
label="Overlap Height Ratio",
|
| 203 |
+
minimum=0.0,
|
| 204 |
+
maximum=1.0,
|
| 205 |
+
step=0.05,
|
| 206 |
+
value=0.2,
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
with gr.Row():
|
| 210 |
+
with gr.Column():
|
| 211 |
+
image_processing_submit_button = gr.Button("Submit")
|
| 212 |
+
|
| 213 |
+
with gr.Row():
|
| 214 |
+
gr.Examples(
|
| 215 |
+
fn=run_predictions,
|
| 216 |
+
examples=IMAGE_PROCESSING_EXAMPLES,
|
| 217 |
+
inputs=[
|
| 218 |
+
image_processing_input_image,
|
| 219 |
+
image_processing_checkpoint_dropdown,
|
| 220 |
+
image_processing_resolution_slider,
|
| 221 |
+
image_processing_confidence_slider,
|
| 222 |
+
slice_height,
|
| 223 |
+
slice_width,
|
| 224 |
+
overlap_height_ratio,
|
| 225 |
+
overlap_width_ratio,
|
| 226 |
+
],
|
| 227 |
+
outputs=[image_processing_output_image],
|
| 228 |
+
run_on_click=True,
|
| 229 |
+
cache_examples=False,
|
| 230 |
+
cache_mode="eager",
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
image_processing_submit_button.click(
|
| 234 |
+
fn=run_predictions,
|
| 235 |
+
inputs=[
|
| 236 |
+
image_processing_input_image,
|
| 237 |
+
image_processing_checkpoint_dropdown,
|
| 238 |
+
image_processing_resolution_slider,
|
| 239 |
+
image_processing_confidence_slider,
|
| 240 |
+
slice_height,
|
| 241 |
+
slice_width,
|
| 242 |
+
overlap_height_ratio,
|
| 243 |
+
overlap_width_ratio,
|
| 244 |
+
],
|
| 245 |
+
outputs=[image_processing_output_image],
|
| 246 |
+
)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
if __name__ == "__main__":
|
| 250 |
+
demo.launch(
|
| 251 |
+
debug=False,
|
| 252 |
+
)
|
pyproject.toml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "rf-detr-sahi"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
requires-python = ">=3.10"
|
| 5 |
+
dependencies = [
|
| 6 |
+
"gradio~=5.35.0",
|
| 7 |
+
"rfdetr~=1.1.0",
|
| 8 |
+
"sahi~=0.11.26",
|
| 9 |
+
]
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio~=5.35.0
|
| 2 |
+
rfdetr~=1.1.0
|
| 3 |
+
sahi~=0.11.26
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|