diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml
new file mode 100644
index 0000000..618a327
--- /dev/null
+++ b/.github/workflows/pylint.yml
@@ -0,0 +1,30 @@
+name: PyLint
+
+on: [push, pull_request]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ python-version: [3.8]
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v2
+ with:
+ python-version: ${{ matrix.python-version }}
+
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install flake8 yapf isort
+
+ # modify the folders accordingly
+ - name: Lint
+ run: |
+ flake8 .
+ isort --check-only --diff basicsr/ options/ scripts/ tests/ inference/ setup.py
+ yapf -r -d basicsr/ options/ scripts/ tests/ inference/ setup.py
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b6c4e54
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,131 @@
+.vscode
+
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+pip-wheel-metadata/
+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/
+
+# 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
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+.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
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__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/
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..03cd47c
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,40 @@
+repos:
+ # flake8
+ - repo: https://github.com/PyCQA/flake8
+ rev: 3.8.3
+ hooks:
+ - id: flake8
+ args: ["--config=setup.cfg", "--ignore=W504, W503"]
+
+ # modify known_third_party
+ - repo: https://github.com/asottile/seed-isort-config
+ rev: v2.2.0
+ hooks:
+ - id: seed-isort-config
+
+ # isort
+ - repo: https://github.com/timothycrosley/isort
+ rev: 5.2.2
+ hooks:
+ - id: isort
+
+ # yapf
+ - repo: https://github.com/pre-commit/mirrors-yapf
+ rev: v0.30.0
+ hooks:
+ - id: yapf
+
+ # pre-commit-hooks
+ - repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: v3.2.0
+ hooks:
+ - id: trailing-whitespace # Trim trailing whitespace
+ - id: check-yaml # Attempt to load all yaml files to verify syntax
+ - id: check-merge-conflict # Check for files that contain merge conflict strings
+ - id: double-quote-string-fixer # Replace double quoted strings with single quoted strings
+ - id: end-of-file-fixer # Make sure files end in a newline and only a newline
+ - id: requirements-txt-fixer # Sort entries in requirements.txt and remove incorrect entry for pkg-resources==0.0.0
+ - id: fix-encoding-pragma # Remove the coding pragma: # -*- coding: utf-8 -*-
+ args: ["--remove"]
+ - id: mixed-line-ending # Replace or check mixed line ending
+ args: ["--fix=lf"]
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f4cf6a7
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2020 Xintao Wang
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..920a663
--- /dev/null
+++ b/README.md
@@ -0,0 +1,81 @@
+# ProjectTemplate-Python
+
+[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/xinntao/HandyView.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/xinntao/HandyView/context:python)
+[![download](https://img.shields.io/github/downloads/xinntao/Real-ESRGAN/total.svg)](https://github.com/xinntao/Real-ESRGAN/releases)
+[![Open issue](https://isitmaintained.com/badge/open/xinntao/basicsr.svg)](https://github.com/xinntao/basicsr/issues)
+[![PyPI](https://img.shields.io/pypi/v/basicsr)](https://pypi.org/project/basicsr/)
+[![LICENSE](https://img.shields.io/github/license/xinntao/basicsr.svg)](https://github.com/xinntao/BasicSR/blob/master/LICENSE/LICENSE)
+[![python lint](https://github.com/xinntao/BasicSR/actions/workflows/pylint.yml/badge.svg)](https://github.com/xinntao/BasicSR/blob/master/.github/workflows/pylint.yml)
+[![Publish-pip](https://github.com/xinntao/BasicSR/actions/workflows/publish-pip.yml/badge.svg)](https://github.com/xinntao/BasicSR/blob/master/.github/workflows/publish-pip.yml)
+[![gitee mirror](https://github.com/xinntao/BasicSR/actions/workflows/gitee-mirror.yml/badge.svg)](https://github.com/xinntao/BasicSR/blob/master/.github/workflows/gitee-mirror.yml)
+
+[English](README.md) **|** [简体中文](README_CN.md) [GitHub](https://github.com/xinntao/ProjectTemplate-Python) **|** [Gitee码云](https://gitee.com/xinntao/ProjectTemplate-Python)
+
+## File Modification
+
+1. Setup *pre-commit* hook
+ 1. If necessary, modify `.pre-commit-config.yaml`
+ 1. In the repository root path, run
+ > pre-commit install
+1. Modify the `.gitignore` file
+1. Modify the `LICENSE` file
+ This repository uses the *MIT* license, you may change it to other licenses
+1. Modify the *setup* files
+ 1. `setup.cfg`
+ 1. `setup.py`, especially the `basicsr` keyword
+1. Modify the `requirements.txt` files
+1. Modify the `VERSION` file
+
+## GitHub Workflows
+
+1. [pylint](./github/workflows/pylint.yml)
+1. [gitee-repo-mirror](./github/workflow/gitee-repo-mirror.yml) - Support Gitee码云
+ 1. Clone GitHub repo in the [Gitee](https://gitee.com/) website
+ 1. Modify [gitee-repo-mirror](./github/workflow/gitee-repo-mirror.yml)
+ 1. In Github *Settings* -> *Secrets*, add `SSH_PRIVATE_KEY`
+
+## Other Procedures
+
+1. The `description`, `website`, `topics` in the main page
+1. Support Chinese documents, for example, `README_CN.md`
+
+## Emoji
+
+[Emoji cheat-sheet](https://github.com/ikatyang/emoji-cheat-sheet)
+
+| Emoji | Meaning |
+| :--- | :---: |
+| :rocket: | Used for [BasicSR](https://github.com/xinntao/BasicSR) Logo |
+| :sparkles: | Features |
+| :zap: | HOWTOs |
+| :wrench: | Installation / Usage |
+| :hourglass_flowing_sand: | TODO list |
+| :turtle: | Dataset preparation |
+| :computer: | Commands |
+| :european_castle: | Model zoo |
+| :memo: | Designs |
+| :scroll: | License and acknowledgement |
+| :earth_asia: | Citations |
+| :e-mail: | Contact |
+| :m: | Models |
+| :arrow_double_down: | Download |
+| :file_folder: | Datasets |
+| :chart_with_upwards_trend: | Curves|
+| :eyes: | Screenshot |
+| :books: |References |
+
+## Useful Image Links
+
+ Google Colab Logo
+ Windows Logo
+ Ubuntu Logo
+
+## Other Useful Tips
+
+1. `More` drop-down menu
+
+ More
+
+ - Nov 19, 2020. Set up ProjectTemplate-Python.
+
+
diff --git a/README_CN.md b/README_CN.md
new file mode 100644
index 0000000..4d6bb1c
--- /dev/null
+++ b/README_CN.md
@@ -0,0 +1,72 @@
+# ProjectTemplate-Python
+
+[English](README.md) **|** [简体中文](README_CN.md) [GitHub](https://github.com/xinntao/ProjectTemplate-Python) **|** [Gitee码云](https://gitee.com/xinntao/ProjectTemplate-Python)
+
+## 文件修改
+
+1. 设置 *pre-commit* hook.
+ 1. 若需要, 修改 `.pre-commit-config.yaml`
+ 1. 在文件夹根目录, 运行
+ > pre-commit install
+1. 修改 `.gitignore` 文件
+1. 修改 `LICENSE` 文件
+ 本仓库使用 *MIT* 许可, 根据需要可以修改成其他许可
+1. 修改 *setup* 文件
+ 1. `setup.cfg`
+ 1. `setup.py`, 特别是其中包含的关键字 `basicsr`
+1. 修改 `requirements.txt` 文件
+1. 修改 `VERSION` 文件
+
+## GitHub Workflows
+
+1. [pylint](./github/workflows/pylint.yml)
+1. [gitee-repo-mirror](./github/workflow/gitee-repo-mirror.yml) - 支持 Gitee码云
+ 1. 在 [Gitee](https://gitee.com/) 网站克隆 Github 仓库
+ 1. 修改 [gitee-repo-mirror](./github/workflow/gitee-repo-mirror.yml) 文件
+ 1. 在 Github 中的 *Settings* -> *Secrets* 的 `SSH_PRIVATE_KEY`
+
+## 其他流程
+
+1. 主页上的 `description`, `website`, `topics`
+1. 支持中文文档, 比如, `README_CN.md`
+
+## Emoji
+
+[Emoji cheat-sheet](https://github.com/ikatyang/emoji-cheat-sheet)
+
+| Emoji | Meaning |
+| :--- | :---: |
+| :rocket: | Used for [BasicSR](https://github.com/xinntao/BasicSR) Logo |
+| :sparkles: | Features |
+| :zap: | HOWTOs |
+| :wrench: | Installation / Usage |
+| :hourglass_flowing_sand: | TODO list |
+| :turtle: | Dataset preparation |
+| :computer: | Commands |
+| :european_castle: | Model zoo |
+| :memo: | Designs |
+| :scroll: | License and acknowledgement |
+| :earth_asia: | Citations |
+| :e-mail: | Contact |
+| :m: | Models |
+| :arrow_double_down: | Download |
+| :file_folder: | Datasets |
+| :chart_with_upwards_trend: | Curves|
+| :eyes: | Screenshot |
+| :books: |References |
+
+## 有用的图像链接
+
+ Google Colab Logo
+ Windows Logo
+ Ubuntu Logo
+
+## 其他有用的技巧
+
+1. `More` 下拉菜单
+
+ More
+
+ - Nov 19, 2020. Set up ProjectTemplate-Python.
+
+
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..77d6f4c
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.0.0
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..24ce15a
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+numpy
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..cd94c8b
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,22 @@
+[flake8]
+ignore =
+ # line break before binary operator (W503)
+ W503,
+ # line break after binary operator (W504)
+ W504,
+max-line-length=120
+
+[yapf]
+based_on_style = pep8
+column_limit = 120
+blank_line_before_nested_class_or_def = true
+split_before_expression_after_opening_paren = true
+
+[isort]
+line_length = 120
+multi_line_output = 0
+known_standard_library = pkg_resources,setuptools
+known_first_party = basicsr # modify it!
+known_third_party = torch
+no_lines_before = STDLIB,LOCALFOLDER
+default_section = THIRDPARTY
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..6501c98
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,160 @@
+#!/usr/bin/env python
+
+from setuptools import find_packages, setup
+
+import os
+import subprocess
+import sys
+import time
+import torch
+from torch.utils.cpp_extension import BuildExtension, CppExtension, CUDAExtension
+
+version_file = 'basicsr/version.py'
+
+
+def readme():
+ with open('README.md', encoding='utf-8') as f:
+ content = f.read()
+ return content
+
+
+def get_git_hash():
+
+ def _minimal_ext_cmd(cmd):
+ # construct minimal environment
+ env = {}
+ for k in ['SYSTEMROOT', 'PATH', 'HOME']:
+ v = os.environ.get(k)
+ if v is not None:
+ env[k] = v
+ # LANGUAGE is used on win32
+ env['LANGUAGE'] = 'C'
+ env['LANG'] = 'C'
+ env['LC_ALL'] = 'C'
+ out = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
+ return out
+
+ try:
+ out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
+ sha = out.strip().decode('ascii')
+ except OSError:
+ sha = 'unknown'
+
+ return sha
+
+
+def get_hash():
+ if os.path.exists('.git'):
+ sha = get_git_hash()[:7]
+ else:
+ sha = 'unknown'
+
+ return sha
+
+
+def write_version_py():
+ content = """# GENERATED VERSION FILE
+# TIME: {}
+__version__ = '{}'
+__gitsha__ = '{}'
+version_info = ({})
+"""
+ sha = get_hash()
+ with open('VERSION', 'r') as f:
+ SHORT_VERSION = f.read().strip()
+ VERSION_INFO = ', '.join([x if x.isdigit() else f'"{x}"' for x in SHORT_VERSION.split('.')])
+
+ version_file_str = content.format(time.asctime(), SHORT_VERSION, sha, VERSION_INFO)
+ with open(version_file, 'w') as f:
+ f.write(version_file_str)
+
+
+def get_version():
+ with open(version_file, 'r') as f:
+ exec(compile(f.read(), version_file, 'exec'))
+ return locals()['__version__']
+
+
+def make_cuda_ext(name, module, sources, sources_cuda=None):
+ if sources_cuda is None:
+ sources_cuda = []
+ define_macros = []
+ extra_compile_args = {'cxx': []}
+
+ if torch.cuda.is_available() or os.getenv('FORCE_CUDA', '0') == '1':
+ define_macros += [('WITH_CUDA', None)]
+ extension = CUDAExtension
+ extra_compile_args['nvcc'] = [
+ '-D__CUDA_NO_HALF_OPERATORS__',
+ '-D__CUDA_NO_HALF_CONVERSIONS__',
+ '-D__CUDA_NO_HALF2_OPERATORS__',
+ ]
+ sources += sources_cuda
+ else:
+ print(f'Compiling {name} without CUDA')
+ extension = CppExtension
+
+ return extension(
+ name=f'{module}.{name}',
+ sources=[os.path.join(*module.split('.'), p) for p in sources],
+ define_macros=define_macros,
+ extra_compile_args=extra_compile_args)
+
+
+def get_requirements(filename='requirements.txt'):
+ here = os.path.dirname(os.path.realpath(__file__))
+ with open(os.path.join(here, filename), 'r') as f:
+ requires = [line.replace('\n', '') for line in f.readlines()]
+ return requires
+
+
+if __name__ == '__main__':
+ if '--cuda_ext' in sys.argv:
+ ext_modules = [
+ make_cuda_ext(
+ name='deform_conv_ext',
+ module='basicsr.ops.dcn',
+ sources=['src/deform_conv_ext.cpp'],
+ sources_cuda=['src/deform_conv_cuda.cpp', 'src/deform_conv_cuda_kernel.cu']),
+ make_cuda_ext(
+ name='fused_act_ext',
+ module='basicsr.ops.fused_act',
+ sources=['src/fused_bias_act.cpp'],
+ sources_cuda=['src/fused_bias_act_kernel.cu']),
+ make_cuda_ext(
+ name='upfirdn2d_ext',
+ module='basicsr.ops.upfirdn2d',
+ sources=['src/upfirdn2d.cpp'],
+ sources_cuda=['src/upfirdn2d_kernel.cu']),
+ ]
+ sys.argv.remove('--cuda_ext')
+ else:
+ ext_modules = []
+
+ write_version_py()
+ setup(
+ name='basicsr',
+ version=get_version(),
+ description='Open Source Image and Video Super-Resolution Toolbox',
+ long_description=readme(),
+ long_description_content_type='text/markdown',
+ author='Xintao Wang',
+ author_email='xintao.wang@outlook.com',
+ keywords='computer vision, restoration, super resolution',
+ url='https://github.com/xinntao/BasicSR',
+ include_package_data=True,
+ packages=find_packages(exclude=('options', 'datasets', 'experiments', 'results', 'tb_logger', 'wandb')),
+ classifiers=[
+ 'Development Status :: 4 - Beta',
+ 'License :: OSI Approved :: Apache Software License',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.7',
+ 'Programming Language :: Python :: 3.8',
+ ],
+ license='Apache License 2.0',
+ setup_requires=['cython', 'numpy'],
+ install_requires=get_requirements(),
+ ext_modules=ext_modules,
+ cmdclass={'build_ext': BuildExtension},
+ zip_safe=False)