├── VERSION
├── requirements.txt
├── setup.cfg
├── .github
└── workflows
│ └── pylint.yml
├── LICENSE
├── .pre-commit-config.yaml
├── .gitignore
├── README_CN.md
├── README.md
└── setup.py
/VERSION:
--------------------------------------------------------------------------------
1 | 0.0.0
2 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | numpy
2 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [flake8]
2 | ignore =
3 | # line break before binary operator (W503)
4 | W503,
5 | # line break after binary operator (W504)
6 | W504,
7 | max-line-length=120
8 |
9 | [yapf]
10 | based_on_style = pep8
11 | column_limit = 120
12 | blank_line_before_nested_class_or_def = true
13 | split_before_expression_after_opening_paren = true
14 |
15 | [isort]
16 | line_length = 120
17 | multi_line_output = 0
18 | known_standard_library = pkg_resources,setuptools
19 | known_first_party = basicsr # modify it!
20 | known_third_party = torch
21 | no_lines_before = STDLIB,LOCALFOLDER
22 | default_section = THIRDPARTY
23 |
--------------------------------------------------------------------------------
/.github/workflows/pylint.yml:
--------------------------------------------------------------------------------
1 | name: PyLint
2 |
3 | on: [push, pull_request]
4 |
5 | jobs:
6 | build:
7 |
8 | runs-on: ubuntu-latest
9 | strategy:
10 | matrix:
11 | python-version: [3.8]
12 |
13 | steps:
14 | - uses: actions/checkout@v2
15 | - name: Set up Python ${{ matrix.python-version }}
16 | uses: actions/setup-python@v2
17 | with:
18 | python-version: ${{ matrix.python-version }}
19 |
20 | - name: Install dependencies
21 | run: |
22 | python -m pip install --upgrade pip
23 | pip install flake8 yapf isort
24 |
25 | # modify the folders accordingly
26 | - name: Lint
27 | run: |
28 | flake8 .
29 | isort --check-only --diff basicsr/ options/ scripts/ tests/ inference/ setup.py
30 | yapf -r -d basicsr/ options/ scripts/ tests/ inference/ setup.py
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Xintao Wang
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.
22 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | repos:
2 | # flake8
3 | - repo: https://github.com/PyCQA/flake8
4 | rev: 3.8.3
5 | hooks:
6 | - id: flake8
7 | args: ["--config=setup.cfg", "--ignore=W504, W503"]
8 |
9 | # modify known_third_party
10 | - repo: https://github.com/asottile/seed-isort-config
11 | rev: v2.2.0
12 | hooks:
13 | - id: seed-isort-config
14 |
15 | # isort
16 | - repo: https://github.com/timothycrosley/isort
17 | rev: 5.2.2
18 | hooks:
19 | - id: isort
20 |
21 | # yapf
22 | - repo: https://github.com/pre-commit/mirrors-yapf
23 | rev: v0.30.0
24 | hooks:
25 | - id: yapf
26 |
27 | # pre-commit-hooks
28 | - repo: https://github.com/pre-commit/pre-commit-hooks
29 | rev: v3.2.0
30 | hooks:
31 | - id: trailing-whitespace # Trim trailing whitespace
32 | - id: check-yaml # Attempt to load all yaml files to verify syntax
33 | - id: check-merge-conflict # Check for files that contain merge conflict strings
34 | - id: double-quote-string-fixer # Replace double quoted strings with single quoted strings
35 | - id: end-of-file-fixer # Make sure files end in a newline and only a newline
36 | - id: requirements-txt-fixer # Sort entries in requirements.txt and remove incorrect entry for pkg-resources==0.0.0
37 | - id: fix-encoding-pragma # Remove the coding pragma: # -*- coding: utf-8 -*-
38 | args: ["--remove"]
39 | - id: mixed-line-ending # Replace or check mixed line ending
40 | args: ["--fix=lf"]
41 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 |
3 | # Byte-compiled / optimized / DLL files
4 | __pycache__/
5 | *.py[cod]
6 | *$py.class
7 |
8 | # C extensions
9 | *.so
10 |
11 | # Distribution / packaging
12 | .Python
13 | build/
14 | develop-eggs/
15 | dist/
16 | downloads/
17 | eggs/
18 | .eggs/
19 | lib/
20 | lib64/
21 | parts/
22 | sdist/
23 | var/
24 | wheels/
25 | pip-wheel-metadata/
26 | share/python-wheels/
27 | *.egg-info/
28 | .installed.cfg
29 | *.egg
30 | MANIFEST
31 |
32 | # PyInstaller
33 | # Usually these files are written by a python script from a template
34 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
35 | *.manifest
36 | *.spec
37 |
38 | # Installer logs
39 | pip-log.txt
40 | pip-delete-this-directory.txt
41 |
42 | # Unit test / coverage reports
43 | htmlcov/
44 | .tox/
45 | .nox/
46 | .coverage
47 | .coverage.*
48 | .cache
49 | nosetests.xml
50 | coverage.xml
51 | *.cover
52 | *.py,cover
53 | .hypothesis/
54 | .pytest_cache/
55 |
56 | # Translations
57 | *.mo
58 | *.pot
59 |
60 | # Django stuff:
61 | *.log
62 | local_settings.py
63 | db.sqlite3
64 | db.sqlite3-journal
65 |
66 | # Flask stuff:
67 | instance/
68 | .webassets-cache
69 |
70 | # Scrapy stuff:
71 | .scrapy
72 |
73 | # Sphinx documentation
74 | docs/_build/
75 |
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 | .python-version
88 |
89 | # pipenv
90 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
91 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
92 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
93 | # install all needed dependencies.
94 | #Pipfile.lock
95 |
96 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
97 | __pypackages__/
98 |
99 | # Celery stuff
100 | celerybeat-schedule
101 | celerybeat.pid
102 |
103 | # SageMath parsed files
104 | *.sage.py
105 |
106 | # Environments
107 | .env
108 | .venv
109 | env/
110 | venv/
111 | ENV/
112 | env.bak/
113 | venv.bak/
114 |
115 | # Spyder project settings
116 | .spyderproject
117 | .spyproject
118 |
119 | # Rope project settings
120 | .ropeproject
121 |
122 | # mkdocs documentation
123 | /site
124 |
125 | # mypy
126 | .mypy_cache/
127 | .dmypy.json
128 | dmypy.json
129 |
130 | # Pyre type checker
131 | .pyre/
132 |
--------------------------------------------------------------------------------
/README_CN.md:
--------------------------------------------------------------------------------
1 | # ProjectTemplate-Python
2 |
3 | [English](README.md) **|** [简体中文](README_CN.md) [GitHub](https://github.com/xinntao/ProjectTemplate-Python) **|** [Gitee码云](https://gitee.com/xinntao/ProjectTemplate-Python)
4 |
5 | ## 文件修改
6 |
7 | 1. 设置 *pre-commit* hook.
8 | 1. 若需要, 修改 `.pre-commit-config.yaml`
9 | 1. 在文件夹根目录, 运行
10 | > pre-commit install
11 | 1. 修改 `.gitignore` 文件
12 | 1. 修改 `LICENSE` 文件
13 | 本仓库使用 *MIT* 许可, 根据需要可以修改成其他许可
14 | 1. 修改 *setup* 文件
15 | 1. `setup.cfg`
16 | 1. `setup.py`, 特别是其中包含的关键字 `basicsr`
17 | 1. 修改 `requirements.txt` 文件
18 | 1. 修改 `VERSION` 文件
19 |
20 | ## GitHub Workflows
21 |
22 | 1. [pylint](./github/workflows/pylint.yml)
23 | 1. [gitee-repo-mirror](./github/workflow/gitee-repo-mirror.yml) - 支持 Gitee码云
24 | 1. 在 [Gitee](https://gitee.com/) 网站克隆 Github 仓库
25 | 1. 修改 [gitee-repo-mirror](./github/workflow/gitee-repo-mirror.yml) 文件
26 | 1. 在 Github 中的 *Settings* -> *Secrets* 的 `SSH_PRIVATE_KEY`
27 |
28 | ## 其他流程
29 |
30 | 1. 主页上的 `description`, `website`, `topics`
31 | 1. 支持中文文档, 比如, `README_CN.md`
32 |
33 | ## Emoji
34 |
35 | [Emoji cheat-sheet](https://github.com/ikatyang/emoji-cheat-sheet)
36 |
37 | | Emoji | Meaning |
38 | | :--- | :---: |
39 | | :rocket: | Used for [BasicSR](https://github.com/xinntao/BasicSR) Logo |
40 | | :sparkles: | Features |
41 | | :zap: | HOWTOs |
42 | | :wrench: | Installation / Usage |
43 | | :hourglass_flowing_sand: | TODO list |
44 | | :turtle: | Dataset preparation |
45 | | :computer: | Commands |
46 | | :european_castle: | Model zoo |
47 | | :memo: | Designs |
48 | | :scroll: | License and acknowledgement |
49 | | :earth_asia: | Citations |
50 | | :e-mail: | Contact |
51 | | :m: | Models |
52 | | :arrow_double_down: | Download |
53 | | :file_folder: | Datasets |
54 | | :chart_with_upwards_trend: | Curves|
55 | | :eyes: | Screenshot |
56 | | :books: |References |
57 |
58 | ## 有用的图像链接
59 |
60 |
Google Colab Logo
61 |
Windows Logo
62 |
Ubuntu Logo
63 |
64 | ## 其他有用的技巧
65 |
66 | 1. `More` 下拉菜单
67 |
68 | More
69 |
70 | - Nov 19, 2020. Set up ProjectTemplate-Python.
71 |
72 |
73 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ProjectTemplate-Python
2 |
3 | [](https://lgtm.com/projects/g/xinntao/HandyView/context:python)
4 | [](https://github.com/xinntao/Real-ESRGAN/releases)
5 | [](https://github.com/xinntao/basicsr/issues)
6 | [](https://pypi.org/project/basicsr/)
7 | [](https://github.com/xinntao/BasicSR/blob/master/LICENSE/LICENSE)
8 | [](https://github.com/xinntao/BasicSR/blob/master/.github/workflows/pylint.yml)
9 | [](https://github.com/xinntao/BasicSR/blob/master/.github/workflows/publish-pip.yml)
10 | [](https://github.com/xinntao/BasicSR/blob/master/.github/workflows/gitee-mirror.yml)
11 |
12 | [English](README.md) **|** [简体中文](README_CN.md) [GitHub](https://github.com/xinntao/ProjectTemplate-Python) **|** [Gitee码云](https://gitee.com/xinntao/ProjectTemplate-Python)
13 |
14 | ## File Modification
15 |
16 | 1. Setup *pre-commit* hook
17 | 1. If necessary, modify `.pre-commit-config.yaml`
18 | 1. In the repository root path, run
19 | > pre-commit install
20 | 1. Modify the `.gitignore` file
21 | 1. Modify the `LICENSE` file
22 | This repository uses the *MIT* license, you may change it to other licenses
23 | 1. Modify the *setup* files
24 | 1. `setup.cfg`
25 | 1. `setup.py`, especially the `basicsr` keyword
26 | 1. Modify the `requirements.txt` files
27 | 1. Modify the `VERSION` file
28 |
29 | ## GitHub Workflows
30 |
31 | 1. [pylint](./github/workflows/pylint.yml)
32 | 1. [gitee-repo-mirror](./github/workflow/gitee-repo-mirror.yml) - Support Gitee码云
33 | 1. Clone GitHub repo in the [Gitee](https://gitee.com/) website
34 | 1. Modify [gitee-repo-mirror](./github/workflow/gitee-repo-mirror.yml)
35 | 1. In Github *Settings* -> *Secrets*, add `SSH_PRIVATE_KEY`
36 |
37 | ## Other Procedures
38 |
39 | 1. The `description`, `website`, `topics` in the main page
40 | 1. Support Chinese documents, for example, `README_CN.md`
41 |
42 | ## Emoji
43 |
44 | [Emoji cheat-sheet](https://github.com/ikatyang/emoji-cheat-sheet)
45 |
46 | | Emoji | Meaning |
47 | | :--- | :---: |
48 | | :rocket: | Used for [BasicSR](https://github.com/xinntao/BasicSR) Logo |
49 | | :sparkles: | Features |
50 | | :zap: | HOWTOs |
51 | | :wrench: | Installation / Usage |
52 | | :hourglass_flowing_sand: | TODO list |
53 | | :turtle: | Dataset preparation |
54 | | :computer: | Commands |
55 | | :european_castle: | Model zoo |
56 | | :memo: | Designs |
57 | | :scroll: | License and acknowledgement |
58 | | :earth_asia: | Citations |
59 | | :e-mail: | Contact |
60 | | :m: | Models |
61 | | :arrow_double_down: | Download |
62 | | :file_folder: | Datasets |
63 | | :chart_with_upwards_trend: | Curves|
64 | | :eyes: | Screenshot |
65 | | :books: |References |
66 |
67 | ## Useful Image Links
68 |
69 |
Google Colab Logo
70 |
Windows Logo
71 |
Ubuntu Logo
72 |
73 | ## Other Useful Tips
74 |
75 | 1. `More` drop-down menu
76 |
77 | More
78 |
79 | - Nov 19, 2020. Set up ProjectTemplate-Python.
80 |
81 |
82 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from setuptools import find_packages, setup
4 |
5 | import os
6 | import subprocess
7 | import sys
8 | import time
9 | import torch
10 | from torch.utils.cpp_extension import BuildExtension, CppExtension, CUDAExtension
11 |
12 | version_file = 'basicsr/version.py'
13 |
14 |
15 | def readme():
16 | with open('README.md', encoding='utf-8') as f:
17 | content = f.read()
18 | return content
19 |
20 |
21 | def get_git_hash():
22 |
23 | def _minimal_ext_cmd(cmd):
24 | # construct minimal environment
25 | env = {}
26 | for k in ['SYSTEMROOT', 'PATH', 'HOME']:
27 | v = os.environ.get(k)
28 | if v is not None:
29 | env[k] = v
30 | # LANGUAGE is used on win32
31 | env['LANGUAGE'] = 'C'
32 | env['LANG'] = 'C'
33 | env['LC_ALL'] = 'C'
34 | out = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
35 | return out
36 |
37 | try:
38 | out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
39 | sha = out.strip().decode('ascii')
40 | except OSError:
41 | sha = 'unknown'
42 |
43 | return sha
44 |
45 |
46 | def get_hash():
47 | if os.path.exists('.git'):
48 | sha = get_git_hash()[:7]
49 | else:
50 | sha = 'unknown'
51 |
52 | return sha
53 |
54 |
55 | def write_version_py():
56 | content = """# GENERATED VERSION FILE
57 | # TIME: {}
58 | __version__ = '{}'
59 | __gitsha__ = '{}'
60 | version_info = ({})
61 | """
62 | sha = get_hash()
63 | with open('VERSION', 'r') as f:
64 | SHORT_VERSION = f.read().strip()
65 | VERSION_INFO = ', '.join([x if x.isdigit() else f'"{x}"' for x in SHORT_VERSION.split('.')])
66 |
67 | version_file_str = content.format(time.asctime(), SHORT_VERSION, sha, VERSION_INFO)
68 | with open(version_file, 'w') as f:
69 | f.write(version_file_str)
70 |
71 |
72 | def get_version():
73 | with open(version_file, 'r') as f:
74 | exec(compile(f.read(), version_file, 'exec'))
75 | return locals()['__version__']
76 |
77 |
78 | def make_cuda_ext(name, module, sources, sources_cuda=None):
79 | if sources_cuda is None:
80 | sources_cuda = []
81 | define_macros = []
82 | extra_compile_args = {'cxx': []}
83 |
84 | if torch.cuda.is_available() or os.getenv('FORCE_CUDA', '0') == '1':
85 | define_macros += [('WITH_CUDA', None)]
86 | extension = CUDAExtension
87 | extra_compile_args['nvcc'] = [
88 | '-D__CUDA_NO_HALF_OPERATORS__',
89 | '-D__CUDA_NO_HALF_CONVERSIONS__',
90 | '-D__CUDA_NO_HALF2_OPERATORS__',
91 | ]
92 | sources += sources_cuda
93 | else:
94 | print(f'Compiling {name} without CUDA')
95 | extension = CppExtension
96 |
97 | return extension(
98 | name=f'{module}.{name}',
99 | sources=[os.path.join(*module.split('.'), p) for p in sources],
100 | define_macros=define_macros,
101 | extra_compile_args=extra_compile_args)
102 |
103 |
104 | def get_requirements(filename='requirements.txt'):
105 | here = os.path.dirname(os.path.realpath(__file__))
106 | with open(os.path.join(here, filename), 'r') as f:
107 | requires = [line.replace('\n', '') for line in f.readlines()]
108 | return requires
109 |
110 |
111 | if __name__ == '__main__':
112 | if '--cuda_ext' in sys.argv:
113 | ext_modules = [
114 | make_cuda_ext(
115 | name='deform_conv_ext',
116 | module='basicsr.ops.dcn',
117 | sources=['src/deform_conv_ext.cpp'],
118 | sources_cuda=['src/deform_conv_cuda.cpp', 'src/deform_conv_cuda_kernel.cu']),
119 | make_cuda_ext(
120 | name='fused_act_ext',
121 | module='basicsr.ops.fused_act',
122 | sources=['src/fused_bias_act.cpp'],
123 | sources_cuda=['src/fused_bias_act_kernel.cu']),
124 | make_cuda_ext(
125 | name='upfirdn2d_ext',
126 | module='basicsr.ops.upfirdn2d',
127 | sources=['src/upfirdn2d.cpp'],
128 | sources_cuda=['src/upfirdn2d_kernel.cu']),
129 | ]
130 | sys.argv.remove('--cuda_ext')
131 | else:
132 | ext_modules = []
133 |
134 | write_version_py()
135 | setup(
136 | name='basicsr',
137 | version=get_version(),
138 | description='Open Source Image and Video Super-Resolution Toolbox',
139 | long_description=readme(),
140 | long_description_content_type='text/markdown',
141 | author='Xintao Wang',
142 | author_email='xintao.wang@outlook.com',
143 | keywords='computer vision, restoration, super resolution',
144 | url='https://github.com/xinntao/BasicSR',
145 | include_package_data=True,
146 | packages=find_packages(exclude=('options', 'datasets', 'experiments', 'results', 'tb_logger', 'wandb')),
147 | classifiers=[
148 | 'Development Status :: 4 - Beta',
149 | 'License :: OSI Approved :: Apache Software License',
150 | 'Operating System :: OS Independent',
151 | 'Programming Language :: Python :: 3',
152 | 'Programming Language :: Python :: 3.7',
153 | 'Programming Language :: Python :: 3.8',
154 | ],
155 | license='Apache License 2.0',
156 | setup_requires=['cython', 'numpy'],
157 | install_requires=get_requirements(),
158 | ext_modules=ext_modules,
159 | cmdclass={'build_ext': BuildExtension},
160 | zip_safe=False)
161 |
--------------------------------------------------------------------------------