- Python >= 3.7 (Recommend to use Anaconda or Miniconda)
- PyTorch >= 1.7
- NVIDIA GPU + CUDA
- Linux (We have not tested on Windows)
If you want to use PyTorch C++ extensions:
deformable convolution: dcn for EDVR (For torchvision>=0.9.0, we use the official torchvision.ops.deform_conv2d
instead)
StyleGAN customized operators: upfirdn2d and fused_act for StyleGAN2
you also need to:
- compile the PyTorch C++ extensions during installation
- OR load the PyTorch C++ extensions just-in-time (JIT)
You may choose one of the options according to your needs.
Option | Pros | Cons | Cases | Env Variable |
---|---|---|---|---|
Compile PyTorch C++ extensions during installation | Quickly load the compiled extensions during running | May have more stringent requirements for the environment, and you may encounter annoying issues | If you need to train/inference those models for many times, it will save your time | Set BASICSR_EXT=True during installation |
Load PyTorch C++ extensions just-in-time (JIT) | Have less requirements, may have less issues | Each time you run the model, it will takes several minutes to load extensions again | If you just want to do simple inferences, it is more convenient | Set BASICSR_JIT=True during running (not installation) |
For those who need to compile the PyTorch C++ extensions during installation, remember:
- Make sure that your gcc and g++ version: gcc & g++ >= 5
Note that:
- The
BASICSR_JIT
has higher priority, that is, even you have successfully compiled PyTorch C++ extensions during installation, it will still load the extensions just-in-time if you setBASICSR_JIT=True
in your running commands. - ❌ Do not set
BASICSR_JIT
during installation. Installation commands are in Installation Options. - ✔️ If you want to load PyTorch C++ extensions just-in-time (JIT), just set
BASICSR_JIT=True
before your running commands. For example,BASICSR_JIT=True python inference/inference_stylegan2.py
.
If you do not need those PyTorch C++ extensions, just skip it. There is no need to set BASICSR_EXT
or BASICSR_JIT
environment variables.
There are two options to install BASICSR, according to your needs.
- If you just want to use BASICSR as a package (just like GFPGAN and ), it is recommended to install from PyPI.
- If you want to investigate the details of BASICSR OR develop it OR modify it to fulfill your needs, it is better to install from a local clone.
-
If you do not need C++ extensions (more details are here):
pip install basicsr
-
If you want to use C++ extensions in JIT mode without compiling them during installatoin (more details are here):
pip install basicsr
-
If you want to compile C++ extensions during installation, please set the environment variable
BASICSR_EXT=True
:BASICSR_EXT=True pip install basicsr
The compilation may fail without any error prints. If you encounter running errors, such as
ImportError: cannot import name 'deform_conv_ext' | 'fused_act_ext' | 'upfirdn2d_ext'
, you may check the compilation process by re-installation. The following command will print detailed log:BASICSR_EXT=True pip install basicsr -vvv
You may also want to specify the CUDA paths:
CUDA_HOME=/usr/local/cuda \ CUDNN_INCLUDE_DIR=/usr/local/cuda \ CUDNN_LIB_DIR=/usr/local/cuda \ BASICSR_EXT=True pip install basicsr
-
Clone the repo
git clone https://github.com/xinntao/BasicSR.git
-
Install dependent packages
cd BasicSR pip install -r requirements.txt
-
Install BasicSR
Please run the following commands in the BasicSR root path to install BasicSR:-
If you do not need C++ extensions (more details are here):
python setup.py develop
-
If you want to use C++ extensions in JIT mode without compiling them during installatoin (more details are here):
python setup.py develop
-
If you want to compile C++ extensions during installation, please set the environment variable
BASICSR_EXT=True
:BASICSR_EXT=True python setup.py develop
You may also want to specify the CUDA paths:
CUDA_HOME=/usr/local/cuda \ CUDNN_INCLUDE_DIR=/usr/local/cuda \ CUDNN_LIB_DIR=/usr/local/cuda \ BASICSR_EXT=True python setup.py develop
-