Skip to content

Commit

Permalink
Initial commit (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohrusky authored Oct 3, 2024
1 parent 49f0a2e commit 53699ba
Show file tree
Hide file tree
Showing 45 changed files with 1,902 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/CI-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI-test

env:
GITHUB_ACTIONS: true

on:
push:
branches: ["main"]
paths-ignore:
- "**.md"
- "LICENSE"

pull_request:
branches: ["main"]
paths-ignore:
- "**.md"
- "LICENSE"

workflow_dispatch:

jobs:
CI:
strategy:
matrix:
os-version: ["ubuntu-20.04", "macos-14", "windows-latest"]
python-version: ["3.9"]
poetry-version: ["1.8.3"]

runs-on: ${{ matrix.os-version }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}

- name: Test
run: |
pip install numpy==1.26.4
pip install pydantic tenacity opencv-python
pip install pre-commit torch torchvision scikit-image
pip install pytest pytest-cov coverage
pip install mypy ruff types-requests
make lint
make test
- name: Codecov
if: matrix.os-version == 'ubuntu-20.04'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/Release-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release-pypi

on:
workflow_dispatch:

jobs:
Pypi:
strategy:
matrix:
python-version: ["3.9"]
poetry-version: ["1.8.3"]

runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}

- name: Build package
run: |
make build
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API }}
171 changes: 171 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

*.DS_Store

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
/.ruff_cache/

/ccrestoration/cache_models/*.pth
/ccrestoration/cache_models/*.pt
/ccrestoration/cache_models/*.pkl

/assets/*_out.jpg

*.mp4
*.mkv
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: check-yaml
- id: check-xml
- id: check-toml

# autofix json, yaml, markdown...
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier

# autofix toml
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.12.0
hooks:
- id: pretty-format-toml
args: [--autofix]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff-format
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
hooks:
- id: mypy
args: [ccrestoration, tests]
pass_filenames: false
additional_dependencies:
- types-requests
- types-certifi
- pytest
- pydantic
- tenacity
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.DEFAULT_GOAL := default

.PHONY: test
test:
poetry run pytest --cov=ccrestoration --cov-report=xml --cov-report=html

.PHONY: lint
lint:
poetry run pre-commit install
poetry run pre-commit run --all-files

.PHONY: build
build:
poetry build --format wheel

.PHONY: vs
vs:
rm -f encoded.mkv
vspipe -c y4m vs.py - | ffmpeg -i - -vcodec libx265 -crf 16 encoded.mkv
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# dev
Binary file added assets/test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions ccrestoration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ccrestoration.auto import AutoModel, AutoConfig # noqa
from ccrestoration.core.type import BaseConfig, ConfigType, BaseModelInterface, ArchType, ModelType # noqa
from ccrestoration.core.model import MODEL_REGISTRY # noqa
from ccrestoration.core.arch import ARCH_REGISTRY # noqa
from ccrestoration.core.config import CONFIG_REGISTRY # noqa
2 changes: 2 additions & 0 deletions ccrestoration/auto/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from ccrestoration.auto.config import AutoConfig # noqa
from ccrestoration.auto.model import AutoModel # noqa
29 changes: 29 additions & 0 deletions ccrestoration/auto/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Any, Optional, Union

from ccrestoration.core.config import CONFIG_REGISTRY
from ccrestoration.core.type import BaseConfig, ConfigType


class AutoConfig:
@staticmethod
def from_pretrained(pretrained_model_name: Union[ConfigType, str]) -> Any:
"""
Get a config instance of a pretrained model configuration.
:param pretrained_model_name: The name of the pretrained model configuration
:return:
"""
return CONFIG_REGISTRY.get(pretrained_model_name)

@staticmethod
def register(config: Union[BaseConfig, Any], name: Optional[str] = None) -> None:
"""
Register the given config class instance under the name BaseConfig.name or the given name.
Can be used as a function call. See docstring of this class for usage.
:param config: The config class instance to register
:param name: The name to register the config class instance under. If None, use BaseConfig.name
:return:
"""
# used as a function call
CONFIG_REGISTRY.register(obj=config, name=name)
Loading

0 comments on commit 53699ba

Please sign in to comment.