How to use the top model HAT in the super resolution category

MLBoy
3 min readOct 25, 2023

Use the top benchmark model

low resolution
high resolution by HAT

install

git clone https://github.com/XPixelGroup/HAT.git
cd HAT
pip install -r requirements.txt
python setup.py develop

Download pre-trained model

pip install — upgrade gdown
gdown https://drive.google.com/u/0/uc?id=1Ma12vCWT27P9M99-s2RXnynKN-OQsBrv

Pre-trained models provided in the repository can be found on Google Drive.

Rewriting the configuration file

Below are the steps to run it with an image you have prepared yourself.

The configuration file for the model in options/test

path:
pretrain_network_g: ./experiments/pretrained_models/Real_HAT_GAN_SRx4.pth

Replace with the path of the pre-trained model file you downloaded earlier.

dataset items

datasets:
test_1: # the 1st test dataset
name: custom
type: SingleImageDataset
dataroot_lq: input_dir
io_backend:
type: disk

and specify the path of the directory containing the image you want to super-resolve in dataroot.

Set the val items to only the following.

val:
save_img: true
suffix: ~ # add suffix to saved images, if None, use exp name

execution

Run the test by specifying the configuration file rewritten above.

python hat/test.py -opt options/test/HAT_GAN_Real_SRx4.yml

Results are saved in the results directory.

Low resolution 644*799
High resolution 2576*3196

The background is now clear.

If you encounter CUDA out of memory, add the following to the configuration file.
Divide the input image into smaller pieces and execute.

tile: # use the tile mode for limited GPU memory when testing.
tile_size: 512 # the higher, the more utilized GPU memory and the less performance change against the full image. must be an integer multiple of the window size.
tile_pad: 32 # overlapping between adjacency patches.must be an integer multiple of the window size.

🐣

I’m a freelance engineer.
Work consultation
Please feel free to contact us with a brief development description.
rockyshikoku@gmail.com

I am creating applications using machine learning and AR technology.

I send machine learning / AR related information.

GitHub

Twitter
Medium

--

--