Official implementation for "Image Quality Assessment using Contrastive Learning"

Overview

Image Quality Assessment using Contrastive Learning

Pavan C. Madhusudana, Neil Birkbeck, Yilin Wang, Balu Adsumilli and Alan C. Bovik

This is the official repository of the paper Image Quality Assessment using Contrastive Learning

Usage

The code has been tested on Linux systems with python 3.6. Please refer to requirements.txt for installing dependent packages.

Running CONTRIQUE

In order to obtain quality score using CONTRIQUE model, checkpoint needs to be downloaded. The following command can be used to download the checkpoint.

wget -L https://utexas.box.com/shared/static/rhpa8nkcfzpvdguo97n2d5dbn4qb03z8.tar -O models/CONTRIQUE_checkpoint25.tar -q --show-progress

Alternatively, the checkpoint can also be downloaded using this link.

Obtaining Quality Scores

We provide trained regressor models in models directory which can be used for predicting image quality using features obtained from CONTRIQUE model. For demonstration purposes, some sample images provided in the sample_images folder.

For blind quality prediction, the following commands can be used.

python3 demo_score.py --im_path sample_images/60.bmp --model_path models/CONTRIQUE_checkpoint25.tar --linear_regressor_path models/CLIVE.save
python3 demo_score.py --im_path sample_images/img66.bmp --model_path models/CONTRIQUE_checkpoint25.tar --linear_regressor_path models/LIVE.save

For Full-reference quality assessment, the folllowing command can be employed.

python3 demos_score_FR.py --ref_path sample_images/churchandcapitol.bmp --dist_path sample_images/img66.bmp --model_path models/CONTRIQUE_checkpoint25.tar --linear_regressor_path models/CSIQ_FR.save

Training CONTRIQUE

Download Training Data

Create a directory mkdir training_data to store images used for training CONTRIQUE.

  1. KADIS-700k : Download KADIS-700k dataset and execute the supllied codes to generate synthetically distorted images. Store this data in the training_data/kadis700k directory.
  2. AVA : Download AVA dataset and store in the training_data/UGC_images/AVA_Dataset directory.
  3. COCO : COCO dataset contains 330k images spread across multiple competitions. We used 4 folders training_data/UGC_images/test2015, training_data/UGC_images/train2017, training_data/UGC_images/val2017, training_data/UGC_images/unlabeled2017 for training.
  4. CERTH-Blur : Blur dataset images are stored in the training_data/UGC_images/blur_image directory.
  5. VOC : VOC images are stored in the training_data/UGC_images/VOC2012 directory.

Training Model

Download csv files containing path to images and corresponding distortion classes.

wget -L https://utexas.box.com/shared/static/124n9sfb27chgt59o8mpxl7tomgvn2lo.csv -O csv_files/file_names_ugc.csv -q --show-progress
wget -L https://utexas.box.com/shared/static/jh5cmu63347auyza37773as5o9zxctby.csv -O csv_files/file_names_syn.csv -q --show-progress

The above files can also be downloaded manually using these links link1, link2

For training with a single GPU the following command can be used

python3 train.py --batch_size 256 --lr 0.6 --epochs 25

Training with multiple GPUs using Distributed training (Recommended)

Run the following commands on different terminals concurrently

CUDA_VISIBLE_DEVICES=0 python3 train.py --nodes 4 --nr 0 --batch_size 64 --lr 0.6 --epochs 25
CUDA_VISIBLE_DEVICES=1 python3 train.py --nodes 4 --nr 1 --batch_size 64 --lr 0.6 --epochs 25
CUDA_VISIBLE_DEVICES=2 python3 train.py --nodes 4 --nr 2 --batch_size 64 --lr 0.6 --epochs 25
CUDA_VISIBLE_DEVICES=3 python3 train.py --nodes 4 --nr 3 --batch_size 64 --lr 0.6 --epochs 25

Note that in distributed training, batch_size value will be the number of images to be loaded on each GPU. During CONTRIQUE training equal number of images will be loaded from both synthetic and authentic distortions. Thus in the above example code, 128 images will be loaded on each GPU.

Training Linear Regressor

After CONTRIQUE model training is complete, a linear regressor is trained using CONTRIQUE features and corresponding ground truth quality scores using the following command.

python3 train_regressor.py --feat_path feat.npy --ground_truth_path scores.npy --alpha 0.1

Contact

Please contact Pavan ([email protected]) if you have any questions, suggestions or corrections to the above implementation.

Citation

@article{madhusudana2021st,
  title={Image Quality Assessment using Contrastive Learning},
  author={Madhusudana, Pavan C and Birkbeck, Neil and Wang, Yilin and Adsumilli, Balu and Bovik, Alan C},
  journal={arXiv:2110.13266},
  year={2021}
}
Comments
  • How to generate feat.npy for the score regressor training?

    How to generate feat.npy for the score regressor training?

    I have made custom data set and labels with Matlab code and the below python scripts:

    def gen_csv(dir_list,
                csv_path,
                ext=".bmp",
                data_mode="syn",
                write_mode="w"):
        """
        Generate CSV file from dir list
        :param data_mode: syn | ref | ugc
        :param write_mode: w | a+
        """
        if len(dir_list) == 0:
            print("[Err]: empty dir list.")
            return
    
        print("Data mode: ", data_mode)
        print("Write mode: ", write_mode)
    
        N_DISTORTIONS = 25
        N_CLS = N_DISTORTIONS * 5 + 1
        print("N_CLS: {:d}".format(N_CLS))
        cnt = 0
        with open(csv_path, write_mode, encoding="utf-8") as f:
            if write_mode != "a+":
                f.write(",Unnamed: 0,File_names,labels\n")
            for dir_path in dir_list:
                print("Processing {:s}...".format(dir_path))
                img_names = [x for x in os.listdir(dir_path) if x.endswith(ext)]
                for img_name in img_names:
                    img_path = dir_path + "/" + img_name
                    if not os.path.isfile(img_path):
                        continue
    
                    print("processing {:s}".format(img_path))
    
                    items = img_name.split(".")[0].split("_")
                    # print(items)
    
                    if len(items) > 3 and data_mode == "syn":
                        distort_type = int(items[-2])
                        distort_level = int(items[-1])
    
                    f.write('{:d},{:d},{:s},"['.format(cnt, cnt, img_path))
    
                    for i in range(N_CLS):
                        if data_mode == "syn":
                            if i == (distort_type - 1) * 5 + (distort_level - 1) + 1:
                                if i == N_CLS - 1:
                                    f.write("1.0")
                                else:
                                    f.write("1.0, ")
                            elif 0 <= i < N_CLS - 1:
                                f.write("0.0, ")
                            elif i == N_CLS - 1:
                                f.write("0.0")
                        elif data_mode == "ref":
                            if i == 0:
                                f.write("1.0, ")
                            elif 0 <= i < N_CLS - 1:
                                f.write("0.0, ")
                            elif i == N_CLS - 1:
                                f.write("0.0")
                        elif data_mode == "ugc":
                            if 0 <= i < N_CLS - 1:
                                f.write("0.0, ")
                            elif i == N_CLS - 1:
                                f.write("0.0")
                        else:
                            print("[Err]: invalid data mode, data mode should be:"
                                  "syn | ref | ugc")
                    f.write(']"\n')
    
                    cnt += 1
    

    the loss reduced from 11.7 to 3.4 now after 29 epoches... image

    How to train the seond stage regressor?

    opened by CaptainEven 5
  • [How to train on custom dataset]

    [How to train on custom dataset]

    Thank you for your excellent work and contribution! I wonder how to train CONTRIQUE on my own datasets, not considering the linear projector training.

    opened by CaptainEven 5
  • About distributed training

    About distributed training

    Is the distributed training set up by you single-machine multi-card or multi-machine multi-card? I ran into NCCL errors training on two Gpus on the same machine

    opened by yongZheng1723 4
  • [Recommendation] Recommendation to provide link of synthesized image distortion scripts.

    [Recommendation] Recommendation to provide link of synthesized image distortion scripts.

    In case of custom dataset training requirements, and to avoid downloading KaDID-30K dataset, it's recommended to provide the link of synthesizing image distortions Matlab scripts. Because the dataset is so large(40+G)...

    opened by CaptainEven 4
  • How to generate score.npy file

    How to generate score.npy file

    Using the provided datasets i am facing an issue regarding the regressor training. I have trained the model but i don't understand how the scores.npy file is generated

    opened by AnastasiaBam 3
  • KADIS-700 link is not working

    KADIS-700 link is not working

    http://database.mmsp-kn.de/kadid-10k-database.html links are not working and alternative link ref_img folder is empty! this data set is very important in your work, i don't know how to train the network without it.

    opened by Kowareta993 2
  • The difference between trainning from image-classification task pretrained model and training from the start

    The difference between trainning from image-classification task pretrained model and training from the start

    When training, I find training with pretrained resnet50 model takes less trainning time.I want to know why the article choose to training from the start without pretrained?

    opened by jczhydy 2
  • How to interpret score values?

    How to interpret score values?

    Hi, thanks for this work. I want to use this metric to evaluate the quality of some image for my research, in both FR and NR mode. I was wondering what is the score range for FR and the score range for NR. How should we interpret this values? For examples, the NR score for churchandcapitol.bmp is 16.765732, but on image66.bmp which is distorted, the NR score is 56.64854 while using the same linear regressor LIVE for both. On the other hand, with CLIVE I obtain NR score 84.52191 for churchandcapitol.bmp and 23.473944 for image66.bmp.

    Higher is better? Lower is better? I've noticed that using different linear regressor the output values are in different ranges.

    I also tried to compute the FR between two identical images (churchandcapitol.bmp) and the results is -0.04409191 with CSIQ_FR linear regressor, and 1.8522606 with linear regressor LIVE_FR. Also, when I compare image 33.bmp with itself I obtain the same value of -0.04409191 with CSIQ_FR and 1.8522606 with LIVE_FR.

    Could you please provide some insights on the interpretation of the scores?

    Thank you for your time. Have a great day.

    opened by Ellyuca 2
  • Finetuning on another dataset

    Finetuning on another dataset

    Hi Found the paper very useful and trying to Finetune on my own dataset. I wanted to know what the loss values looked like for your dataset. According to the experiments I am running, the loss doesn't converge and is stuck around 3.9-4 even after extensive training.

    • my dataset contains around 2.5 L image (100k synthetic + 150k UGC).
    • Using a learning rate of 0.001 for later epochs. Any Ideas on how to improve the training regimen so that the model converges?
    opened by nishantb06 1
  • How to train custom dataset

    How to train custom dataset

    @pavancm Hi all,

    I am looking to train a model using custom dataset where I have only image. Can you please help me out with any explanation, idea for training process. Please tell me step by step for training with my data

    Thanks!!

    opened by ThangTo 1
  • [Recommendation] Recommendation to provide link of synthesized image distortion scripts.

    [Recommendation] Recommendation to provide link of synthesized image distortion scripts.

    In case of custom dataset training requirements, and to avoid download KaDID-30K dataset, it's recommended to provide the link of synthesizing iamge distortions Matlab scripts. Because the dataset is so large(40+G)...

    opened by CaptainEven 0
  • About MS-colorspace

    About MS-colorspace

    I have tried training for different color space,and get similar result in RGB、Graysacle.But I failed to get a good result in MS-colorspace.Is there are something special I should take into consider when training through MS-colorspace?And is large amount of data for pretraining essential?

    opened by jczhydy 6
  • performance of supervised finetune using CONTRIQUE?

    performance of supervised finetune using CONTRIQUE?

    Hello,I wonder the performance of supervised finetune using CONTRIQUE encoder compared to imagenet pretrained model, but I can't find such exp in paper.

    can you share the results if you have done such exp, Thanks.

    opened by xinyeCH 1
Owner
Pavan Chennagiri
PhD Student
Pavan Chennagiri
Official PyTorch implementation for paper Context Matters: Graph-based Self-supervised Representation Learning for Medical Images

Context Matters: Graph-based Self-supervised Representation Learning for Medical Images Official PyTorch implementation for paper Context Matters: Gra

null 49 Nov 23, 2022
The official implementation of NeMo: Neural Mesh Models of Contrastive Features for Robust 3D Pose Estimation [ICLR-2021]. https://arxiv.org/pdf/2101.12378.pdf

NeMo: Neural Mesh Models of Contrastive Features for Robust 3D Pose Estimation [ICLR-2021] Release Notes The offical PyTorch implementation of NeMo, p

Angtian Wang 76 Nov 23, 2022
StyleGAN2-ADA - Official PyTorch implementation

Abstract: Training generative adversarial networks (GAN) using too little data typically leads to discriminator overfitting, causing training to diverge. We propose an adaptive discriminator augmentation mechanism that significantly stabilizes training in limited data regimes.

NVIDIA Research Projects 3.2k Dec 30, 2022
Official implementation of the ICLR 2021 paper

You Only Need Adversarial Supervision for Semantic Image Synthesis Official PyTorch implementation of the ICLR 2021 paper "You Only Need Adversarial S

Bosch Research 272 Dec 28, 2022
Official PyTorch implementation of Joint Object Detection and Multi-Object Tracking with Graph Neural Networks

This is the official PyTorch implementation of our paper: "Joint Object Detection and Multi-Object Tracking with Graph Neural Networks". Our project website and video demos are here.

Richard Wang 443 Dec 6, 2022
Official implementation of the paper Image Generators with Conditionally-Independent Pixel Synthesis https://arxiv.org/abs/2011.13775

CIPS -- Official Pytorch Implementation of the paper Image Generators with Conditionally-Independent Pixel Synthesis Requirements pip install -r requi

Multimodal Lab @ Samsung AI Center Moscow 201 Dec 21, 2022
Official pytorch implementation of paper "Image-to-image Translation via Hierarchical Style Disentanglement".

HiSD: Image-to-image Translation via Hierarchical Style Disentanglement Official pytorch implementation of paper "Image-to-image Translation

null 364 Dec 14, 2022
Official pytorch implementation of paper "Inception Convolution with Efficient Dilation Search" (CVPR 2021 Oral).

IC-Conv This repository is an official implementation of the paper Inception Convolution with Efficient Dilation Search. Getting Started Download Imag

Jie Liu 111 Dec 31, 2022
Official PyTorch Implementation of Unsupervised Learning of Scene Flow Estimation Fusing with Local Rigidity

UnRigidFlow This is the official PyTorch implementation of UnRigidFlow (IJCAI2019). Here are two sample results (~10MB gif for each) of our unsupervis

Liang Liu 28 Nov 16, 2022
Official implementation of our paper "LLA: Loss-aware Label Assignment for Dense Pedestrian Detection" in Pytorch.

LLA: Loss-aware Label Assignment for Dense Pedestrian Detection This project provides an implementation for "LLA: Loss-aware Label Assignment for Dens

null 35 Dec 6, 2022
Official implementation of Self-supervised Graph Attention Networks (SuperGAT), ICLR 2021.

SuperGAT Official implementation of Self-supervised Graph Attention Networks (SuperGAT). This model is presented at How to Find Your Friendly Neighbor

Dongkwan Kim 127 Dec 28, 2022
An official implementation of "SFNet: Learning Object-aware Semantic Correspondence" (CVPR 2019, TPAMI 2020) in PyTorch.

PyTorch implementation of SFNet This is the implementation of the paper "SFNet: Learning Object-aware Semantic Correspondence". For more information,

CV Lab @ Yonsei University 87 Dec 30, 2022
This project is the official implementation of our accepted ICLR 2021 paper BiPointNet: Binary Neural Network for Point Clouds.

BiPointNet: Binary Neural Network for Point Clouds Created by Haotong Qin, Zhongang Cai, Mingyuan Zhang, Yifu Ding, Haiyu Zhao, Shuai Yi, Xianglong Li

Haotong Qin 59 Dec 17, 2022
Official code implementation for "Personalized Federated Learning using Hypernetworks"

Personalized Federated Learning using Hypernetworks This is an official implementation of Personalized Federated Learning using Hypernetworks paper. [

Aviv Shamsian 121 Dec 25, 2022
StyleGAN2 - Official TensorFlow Implementation

StyleGAN2 - Official TensorFlow Implementation

NVIDIA Research Projects 10.1k Dec 28, 2022
Old Photo Restoration (Official PyTorch Implementation)

Bringing Old Photo Back to Life (CVPR 2020 oral)

Microsoft 11.3k Dec 30, 2022
Official implementation of "GS-WGAN: A Gradient-Sanitized Approach for Learning Differentially Private Generators" (NeurIPS 2020)

GS-WGAN This repository contains the implementation for GS-WGAN: A Gradient-Sanitized Approach for Learning Differentially Private Generators (NeurIPS

null 46 Nov 9, 2022
Official PyTorch implementation of Spatial Dependency Networks.

Spatial Dependency Networks: Neural Layers for Improved Generative Image Modeling Đorđe Miladinović   Aleksandar Stanić   Stefan Bauer   Jürgen Schmid

Djordje Miladinovic 34 Jan 19, 2022
Official implementation of YOGO for Point-Cloud Processing

You Only Group Once: Efficient Point-Cloud Processing with Token Representation and Relation Inference Module By Chenfeng Xu, Bohan Zhai, Bichen Wu, T

Chenfeng Xu 67 Dec 20, 2022