nobg 0.1.0rc0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nobg-0.1.0rc0/.github/workflows/lint.yml +25 -0
- nobg-0.1.0rc0/.github/workflows/publish.yml +26 -0
- nobg-0.1.0rc0/.gitignore +219 -0
- nobg-0.1.0rc0/.python-version +1 -0
- nobg-0.1.0rc0/AGENTS.md +145 -0
- nobg-0.1.0rc0/CONTRIBUTING.md +39 -0
- nobg-0.1.0rc0/LICENSE +21 -0
- nobg-0.1.0rc0/PKG-INFO +77 -0
- nobg-0.1.0rc0/README.md +49 -0
- nobg-0.1.0rc0/assets/feyn_mark.png +0 -0
- nobg-0.1.0rc0/pyproject.toml +56 -0
- nobg-0.1.0rc0/src/nobg/__init__.py +8 -0
- nobg-0.1.0rc0/src/nobg/ann/__init__.py +0 -0
- nobg-0.1.0rc0/src/nobg/ann/modeling_ann.py +31 -0
- nobg-0.1.0rc0/src/nobg/auto.py +28 -0
- nobg-0.1.0rc0/src/nobg/birefnet/__init__.py +0 -0
- nobg-0.1.0rc0/src/nobg/birefnet/modeling_birefnet.py +911 -0
- nobg-0.1.0rc0/src/nobg/gpt2/__init__.py +0 -0
- nobg-0.1.0rc0/src/nobg/gpt2/modeling_gpt2.py +150 -0
- nobg-0.1.0rc0/src/nobg/loss.py +37 -0
- nobg-0.1.0rc0/src/nobg/mixin.py +52 -0
- nobg-0.1.0rc0/src/nobg/utils.py +50 -0
- nobg-0.1.0rc0/tests/test_ann.py +70 -0
- nobg-0.1.0rc0/tests/test_birefnet.py +106 -0
- nobg-0.1.0rc0/tests/test_gpt2.py +127 -0
- nobg-0.1.0rc0/uv.lock +3282 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Lint
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
ruff:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: astral-sh/setup-uv@v6
|
|
15
|
+
- run: uv sync
|
|
16
|
+
- run: uv run ruff check src/ tests/
|
|
17
|
+
- run: uv run ruff format --check src/ tests/
|
|
18
|
+
|
|
19
|
+
ty:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v4
|
|
23
|
+
- uses: astral-sh/setup-uv@v6
|
|
24
|
+
- run: uv sync
|
|
25
|
+
- run: uvx ty check src/
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
|
|
13
|
+
- uses: actions/setup-python@v5
|
|
14
|
+
with:
|
|
15
|
+
python-version: "3.13"
|
|
16
|
+
|
|
17
|
+
- name: Install build tools
|
|
18
|
+
run: pip install build
|
|
19
|
+
|
|
20
|
+
- name: Build package
|
|
21
|
+
run: python -m build
|
|
22
|
+
|
|
23
|
+
- name: Publish to PyPI
|
|
24
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
25
|
+
with:
|
|
26
|
+
password: ${{ secrets.PYPI_TOKEN }}
|
nobg-0.1.0rc0/.gitignore
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
# !downloads/test.py
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py.cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# UV
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi
|
|
127
|
+
|
|
128
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
129
|
+
__pypackages__/
|
|
130
|
+
|
|
131
|
+
# Celery stuff
|
|
132
|
+
celerybeat-schedule
|
|
133
|
+
celerybeat.pid
|
|
134
|
+
|
|
135
|
+
# Redis
|
|
136
|
+
*.rdb
|
|
137
|
+
*.aof
|
|
138
|
+
*.pid
|
|
139
|
+
|
|
140
|
+
# RabbitMQ
|
|
141
|
+
mnesia/
|
|
142
|
+
rabbitmq/
|
|
143
|
+
rabbitmq-data/
|
|
144
|
+
|
|
145
|
+
# ActiveMQ
|
|
146
|
+
activemq-data/
|
|
147
|
+
|
|
148
|
+
# SageMath parsed files
|
|
149
|
+
*.sage.py
|
|
150
|
+
|
|
151
|
+
# Environments
|
|
152
|
+
.env
|
|
153
|
+
.envrc
|
|
154
|
+
.venv
|
|
155
|
+
env/
|
|
156
|
+
venv/
|
|
157
|
+
ENV/
|
|
158
|
+
env.bak/
|
|
159
|
+
venv.bak/
|
|
160
|
+
|
|
161
|
+
# Spyder project settings
|
|
162
|
+
.spyderproject
|
|
163
|
+
.spyproject
|
|
164
|
+
|
|
165
|
+
# Rope project settings
|
|
166
|
+
.ropeproject
|
|
167
|
+
|
|
168
|
+
# mkdocs documentation
|
|
169
|
+
/site
|
|
170
|
+
|
|
171
|
+
# mypy
|
|
172
|
+
.mypy_cache/
|
|
173
|
+
.dmypy.json
|
|
174
|
+
dmypy.json
|
|
175
|
+
|
|
176
|
+
# Pyre type checker
|
|
177
|
+
.pyre/
|
|
178
|
+
|
|
179
|
+
# pytype static type analyzer
|
|
180
|
+
.pytype/
|
|
181
|
+
|
|
182
|
+
# Cython debug symbols
|
|
183
|
+
cython_debug/
|
|
184
|
+
|
|
185
|
+
# PyCharm
|
|
186
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
187
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
188
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
189
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
190
|
+
# .idea/
|
|
191
|
+
|
|
192
|
+
# Abstra
|
|
193
|
+
# Abstra is an AI-powered process automation framework.
|
|
194
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
195
|
+
# Learn more at https://abstra.io/docs
|
|
196
|
+
.abstra/
|
|
197
|
+
|
|
198
|
+
# Visual Studio Code
|
|
199
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
200
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
201
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
202
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
203
|
+
# .vscode/
|
|
204
|
+
# Temporary file for partial code execution
|
|
205
|
+
tempCodeRunnerFile.py
|
|
206
|
+
|
|
207
|
+
# Ruff stuff:
|
|
208
|
+
.ruff_cache/
|
|
209
|
+
|
|
210
|
+
# PyPI configuration file
|
|
211
|
+
.pypirc
|
|
212
|
+
|
|
213
|
+
# Marimo
|
|
214
|
+
marimo/_static/
|
|
215
|
+
marimo/_lsp/
|
|
216
|
+
__marimo__/
|
|
217
|
+
|
|
218
|
+
# Streamlit
|
|
219
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
nobg-0.1.0rc0/AGENTS.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Architecture Rules
|
|
2
|
+
|
|
3
|
+
This document defines the architectural invariants that all future models and contributions must respect.
|
|
4
|
+
|
|
5
|
+
## Project Layout
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
src/nobg/
|
|
9
|
+
├── __init__.py # Public API exports (all model classes + AutoModel)
|
|
10
|
+
├── auto.py # AutoModel factory (tag-based dispatch)
|
|
11
|
+
├── mixin.py # Revised_Mixin (extends PyTorchModelHubMixin)
|
|
12
|
+
├── utils.py # set_doc decorator + model_card_template()
|
|
13
|
+
└── <model_name>/
|
|
14
|
+
├── __init__.py
|
|
15
|
+
└── modeling_<model_name>.py # Config dataclass + model class
|
|
16
|
+
tests/
|
|
17
|
+
└── test_<model_name>.py # One test file per model (one TestClass per model)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Each model lives in its own subdirectory under `src/nobg/`. The module must be named `modeling_<name>.py`.
|
|
21
|
+
|
|
22
|
+
## Configuration: Dataclass-Only Parameters
|
|
23
|
+
|
|
24
|
+
All model hyperparameters **must** be defined in a `@dataclass` named `<ModelName>Config`:
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
@dataclass
|
|
28
|
+
class ExampleConfig:
|
|
29
|
+
hidden_size: int = 256
|
|
30
|
+
num_layers: int = 4
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Rules:
|
|
34
|
+
- Every field must have a default value (the model must be instantiable with no arguments).
|
|
35
|
+
- For config dataclass fields, only use primitive types (`int`, `float`, `str`, `bool`) and simple containers (`list`, `tuple`) as field types.
|
|
36
|
+
- The config dataclass is the single source of truth for all architectural parameters.
|
|
37
|
+
- Config is serialized to `config.json` by the HuggingFace Hub mixin — no custom serialization logic.
|
|
38
|
+
|
|
39
|
+
## Model Class Structure
|
|
40
|
+
|
|
41
|
+
Every model must inherit from both `nn.Module` and `Revised_Mixin`, passing Hub metadata as class kwargs:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
class MyModel(
|
|
45
|
+
nn.Module,
|
|
46
|
+
Revised_Mixin,
|
|
47
|
+
library_name="nobg",
|
|
48
|
+
repo_url="https://github.com/feyninc/nobg",
|
|
49
|
+
tags=["nobg", "<model-tag>"],
|
|
50
|
+
model_card_template=model_card_template(class_name="MyModel", default_repo="nobg/<model-tag>"),
|
|
51
|
+
):
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Constructor contract:
|
|
55
|
+
- Signature: `def __init__(self, config: Optional[MyModelConfig] = None)`
|
|
56
|
+
- First line after `super().__init__()` must be `self.config = config or MyModelConfig()`
|
|
57
|
+
- All layer construction must derive dimensions from `self.config` fields — no magic numbers.
|
|
58
|
+
|
|
59
|
+
## Inheritance Chain
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
nn.Module + Revised_Mixin → ConcreteModel
|
|
63
|
+
↑
|
|
64
|
+
PyTorchModelHubMixin (huggingface_hub)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- `Revised_Mixin` provides `push_to_hub()` with auto-prefixed `repo_id` and model card injection.
|
|
68
|
+
- Do **not** override `save_pretrained` or `from_pretrained` — these are handled by the Hub mixin.
|
|
69
|
+
- Do **not** introduce new base classes between `Revised_Mixin` and concrete models.
|
|
70
|
+
|
|
71
|
+
## Model Card Template
|
|
72
|
+
|
|
73
|
+
Every model must pass a `model_card_template` kwarg generated by `utils.model_card_template()`:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
model_card_template=model_card_template(class_name="MyModel", default_repo="nobg/my-model")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
This generates a Jinja2 template with:
|
|
80
|
+
- YAML front-matter (`{{ card_data }}`) for Hub metadata
|
|
81
|
+
- Load instructions via `AutoModel` and the direct class
|
|
82
|
+
- Contribution link
|
|
83
|
+
|
|
84
|
+
Do not write custom model card templates — use the shared function.
|
|
85
|
+
|
|
86
|
+
## Tags and AutoModel Registration
|
|
87
|
+
|
|
88
|
+
Models self-declare tags in the class definition. The `tags` list must include:
|
|
89
|
+
1. `"nobg"` (required for all models in this library)
|
|
90
|
+
2. A unique model identifier tag (e.g., `"gpt2"`, `"ann"`) used for AutoModel dispatch
|
|
91
|
+
|
|
92
|
+
`auto.py` dispatches on these tags. When adding a new model:
|
|
93
|
+
1. Append a new `elif "<tag>" in tags` branch at the end of the existing dispatch chain in `AutoModel.from_pretrained()`, before any final `else` or `raise` clause.
|
|
94
|
+
2. Import the model class at the top of `auto.py`
|
|
95
|
+
|
|
96
|
+
## Public API (`__init__.py`)
|
|
97
|
+
|
|
98
|
+
Every model class must be exported from `src/nobg/__init__.py`. Users must be able to do:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from nobg import MyModel, AutoModel
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Tests
|
|
105
|
+
|
|
106
|
+
Each model gets its own test file: `tests/test_<model_name>.py`, containing one `class Test<ModelName>`.
|
|
107
|
+
|
|
108
|
+
Required test coverage for every model:
|
|
109
|
+
|
|
110
|
+
| Test | Purpose |
|
|
111
|
+
|------|---------|
|
|
112
|
+
| `test_init_default_config` | Default config produces valid model |
|
|
113
|
+
| `test_init_custom_config` | Custom config is respected |
|
|
114
|
+
| `test_forward` | Output shape is correct |
|
|
115
|
+
| `test_forward_batch` | Batched input works |
|
|
116
|
+
| `test_save_pretrained` | Produces `model.safetensors` + `config.json` |
|
|
117
|
+
| `test_save_pretrained_config_content` | `config.json` matches config fields exactly |
|
|
118
|
+
| `test_from_pretrained_roundtrip` | Load reconstructs correct config and architecture |
|
|
119
|
+
| `test_weights_preserved_after_roundtrip` | Loaded model produces identical outputs |
|
|
120
|
+
|
|
121
|
+
Tests must be local-only (no network calls). Use `tmp_path` for filesystem operations. Use `@pytest.fixture` for expensive setup (reduced-size configs for large models).
|
|
122
|
+
|
|
123
|
+
## Linting and Type Checking
|
|
124
|
+
|
|
125
|
+
- **Formatter/linter**: `ruff` (check + format)
|
|
126
|
+
- **Type checker**: `ty`
|
|
127
|
+
- Both run in CI on push/PR to `main`
|
|
128
|
+
- Python 3.13+ type syntax is expected (e.g., `list[str]`, `dict[str, Any]`, `tuple[...]`); for config dataclass fields, follow the stricter type rules in the Configuration section.
|
|
129
|
+
|
|
130
|
+
## Dependencies
|
|
131
|
+
|
|
132
|
+
- `torch>=2.0` — core framework
|
|
133
|
+
- `huggingface_hub>=1.22.0` — Hub integration and mixin
|
|
134
|
+
- `transformers>=5.0` — reusable building blocks (e.g., `GPT2Block`)
|
|
135
|
+
|
|
136
|
+
Models may import sub-components from `transformers` but must wrap them behind the nobg config dataclass — the user-facing config is always the nobg `@dataclass`, never a transformers config object directly. When a transformers sub-component requires its own config object (e.g., `GPT2Config`), construct that config object inside `__init__` from `self.config` fields; it must never be stored on `self` or exposed publicly. Example: `gpt2_cfg = GPT2Config(n_embd=self.config.hidden_size, n_layer=self.config.num_layers); self.block = GPT2Block(gpt2_cfg)`.
|
|
137
|
+
|
|
138
|
+
## What NOT to Do
|
|
139
|
+
|
|
140
|
+
- Do not store parameters outside the config dataclass (no loose `__init__` kwargs).
|
|
141
|
+
- Do not use JSON/YAML/TOML files for config definition — the dataclass IS the schema.
|
|
142
|
+
- Do not add CLI entry points — this is a library-only package.
|
|
143
|
+
- Do not introduce plugin/entry-point discovery — models are registered manually.
|
|
144
|
+
- Do not override `save_pretrained` or `from_pretrained`.
|
|
145
|
+
- Do not skip the `model_card_template()` utility.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Contributing to nobg
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
git clone https://github.com/feyninc/nobg.git
|
|
7
|
+
cd nobg
|
|
8
|
+
uv sync
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Development
|
|
12
|
+
|
|
13
|
+
### Running tests
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
uv run pytest tests/
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Linting
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uv run ruff check src/ tests/
|
|
23
|
+
uv run ruff format src/ tests/
|
|
24
|
+
uvx ty check src/
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Adding a new model
|
|
28
|
+
|
|
29
|
+
1. Create `src/nobg/modeling_<name>.py`
|
|
30
|
+
2. Define a config dataclass and model class inheriting from `nn.Module` and `Revised_Mixin`
|
|
31
|
+
3. Use `model_card_template()` from `utils.py` for the HuggingFace model card
|
|
32
|
+
4. Register the model in `__init__.py` and `auto.py`
|
|
33
|
+
5. Add tests in `tests/`
|
|
34
|
+
|
|
35
|
+
## Pull requests
|
|
36
|
+
|
|
37
|
+
- Run the full lint and test suite before opening a PR
|
|
38
|
+
- Keep PRs focused on a single change
|
|
39
|
+
- Add tests for new functionality
|
nobg-0.1.0rc0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Feyn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
nobg-0.1.0rc0/PKG-INFO
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nobg
|
|
3
|
+
Version: 0.1.0rc0
|
|
4
|
+
Summary: Open source background removal models for image and video matting
|
|
5
|
+
Project-URL: Homepage, https://github.com/feyninc/nobg
|
|
6
|
+
Project-URL: Repository, https://github.com/feyninc/nobg
|
|
7
|
+
Project-URL: Issues, https://github.com/feyninc/nobg/issues
|
|
8
|
+
Author-email: Hafedh Hichri <lain@chonkie.ai>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: background-removal,deep-learning,huggingface,matting,pytorch
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
20
|
+
Requires-Python: >=3.13
|
|
21
|
+
Requires-Dist: datasets>=5.0.0
|
|
22
|
+
Requires-Dist: huggingface-hub>=1.22.0
|
|
23
|
+
Requires-Dist: loadimg>=0.5.0
|
|
24
|
+
Requires-Dist: torch>=2.0
|
|
25
|
+
Requires-Dist: torchvision>=0.27.1
|
|
26
|
+
Requires-Dist: transformers[torch]>=5.0
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# nobg
|
|
30
|
+
|
|
31
|
+
A library for image and video matting with HuggingFace Hub integration.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install nobg
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
### AutoModel
|
|
42
|
+
|
|
43
|
+
Automatically detect and load the correct model architecture from a HuggingFace repo:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from nobg import AutoModel
|
|
47
|
+
|
|
48
|
+
model = AutoModel.from_pretrained("nobg/BiRefNet")
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Load a specific model
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from nobg import ANN, GPT2, BiRefNet
|
|
55
|
+
|
|
56
|
+
model = ANN.from_pretrained("nobg/ann")
|
|
57
|
+
model = GPT2.from_pretrained("nobg/gpt2")
|
|
58
|
+
model = BiRefNet.from_pretrained("nobg/BiRefNet")
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Push to HuggingFace Hub
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
model.push_to_hub("your-username/model-name")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Citation
|
|
68
|
+
|
|
69
|
+
```bibtex
|
|
70
|
+
@software{nobg,
|
|
71
|
+
title={nobg: Open Source Background Removal Models for Image and Video Matting},
|
|
72
|
+
author={Hichri, Hafedh},
|
|
73
|
+
year={2026},
|
|
74
|
+
url={https://github.com/feyninc/nobg},
|
|
75
|
+
license={MIT},
|
|
76
|
+
}
|
|
77
|
+
```
|
nobg-0.1.0rc0/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# nobg
|
|
2
|
+
|
|
3
|
+
A library for image and video matting with HuggingFace Hub integration.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install nobg
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### AutoModel
|
|
14
|
+
|
|
15
|
+
Automatically detect and load the correct model architecture from a HuggingFace repo:
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from nobg import AutoModel
|
|
19
|
+
|
|
20
|
+
model = AutoModel.from_pretrained("nobg/BiRefNet")
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Load a specific model
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from nobg import ANN, GPT2, BiRefNet
|
|
27
|
+
|
|
28
|
+
model = ANN.from_pretrained("nobg/ann")
|
|
29
|
+
model = GPT2.from_pretrained("nobg/gpt2")
|
|
30
|
+
model = BiRefNet.from_pretrained("nobg/BiRefNet")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Push to HuggingFace Hub
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
model.push_to_hub("your-username/model-name")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Citation
|
|
40
|
+
|
|
41
|
+
```bibtex
|
|
42
|
+
@software{nobg,
|
|
43
|
+
title={nobg: Open Source Background Removal Models for Image and Video Matting},
|
|
44
|
+
author={Hichri, Hafedh},
|
|
45
|
+
year={2026},
|
|
46
|
+
url={https://github.com/feyninc/nobg},
|
|
47
|
+
license={MIT},
|
|
48
|
+
}
|
|
49
|
+
```
|
|
Binary file
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "nobg"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
description = "Open source background removal models for image and video matting"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
requires-python = ">=3.13"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Hafedh Hichri", email = "lain@chonkie.ai" },
|
|
10
|
+
]
|
|
11
|
+
keywords = ["matting", "background-removal", "deep-learning", "pytorch", "huggingface"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Intended Audience :: Science/Research",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Image Processing",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"torch>=2.0",
|
|
24
|
+
"huggingface_hub>=1.22.0",
|
|
25
|
+
"transformers[torch]>=5.0",
|
|
26
|
+
"torchvision>=0.27.1",
|
|
27
|
+
"loadimg>=0.5.0",
|
|
28
|
+
"datasets>=5.0.0",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[dependency-groups]
|
|
32
|
+
dev = [
|
|
33
|
+
"pytest>=9.0",
|
|
34
|
+
"ruff>=0.15",
|
|
35
|
+
"ty>=0.0.57",
|
|
36
|
+
]
|
|
37
|
+
notebooks = [
|
|
38
|
+
"jupyter>=1.0",
|
|
39
|
+
"ipykernel>=6.0",
|
|
40
|
+
"matplotlib>=3.0",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[project.urls]
|
|
44
|
+
Homepage = "https://github.com/feyninc/nobg"
|
|
45
|
+
Repository = "https://github.com/feyninc/nobg"
|
|
46
|
+
Issues = "https://github.com/feyninc/nobg/issues"
|
|
47
|
+
|
|
48
|
+
[build-system]
|
|
49
|
+
requires = ["hatchling"]
|
|
50
|
+
build-backend = "hatchling.build"
|
|
51
|
+
|
|
52
|
+
[tool.hatch.version]
|
|
53
|
+
path = "src/nobg/__init__.py"
|
|
54
|
+
|
|
55
|
+
[tool.hatch.build.targets.wheel]
|
|
56
|
+
packages = ["src/nobg"]
|
|
File without changes
|