All Projects → AgentMaker → Paddle-PerceptualSimilarity

AgentMaker / Paddle-PerceptualSimilarity

Licence: BSD-2-Clause license
LPIPS metric on PaddlePaddle. pip install paddle-lpips

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to Paddle-PerceptualSimilarity

Perceptualsimilarity
LPIPS metric. pip install lpips
Stars: ✭ 2,037 (+9159.09%)
Mutual labels:  perceptual-losses, perceptual-metric, perceptual-similarity
Paddle-SEQ
低代码序列数据处理框架,最短两行即可完成训练任务!
Stars: ✭ 13 (-40.91%)
Mutual labels:  paddle, paddlepaddle
Paddle-Adversarial-Toolbox
Paddle-Adversarial-Toolbox (PAT) is a Python library for Deep Learning Security based on PaddlePaddle.
Stars: ✭ 16 (-27.27%)
Mutual labels:  paddle, paddlepaddle
PLSC
Paddle Large Scale Classification Tools,supports ArcFace, CosFace, PartialFC, Data Parallel + Model Parallel. Model includes ResNet, ViT, DeiT, FaceViT.
Stars: ✭ 113 (+413.64%)
Mutual labels:  paddle, paddlepaddle
PaddleTokenizer
使用 PaddlePaddle 实现基于深度神经网络的中文分词引擎 | A DNN Chinese Tokenizer by Using PaddlePaddle
Stars: ✭ 14 (-36.36%)
Mutual labels:  paddle, paddlepaddle
PP-YOLO
PaddlePaddle实现的目标检测模型PP-YOLO
Stars: ✭ 59 (+168.18%)
Mutual labels:  paddlepaddle
PAPC
PAPC is a deep learning for point clouds platform based on pure PaddlePaddle
Stars: ✭ 55 (+150%)
Mutual labels:  paddlepaddle
QPT
[内测中]前向式Python环境快捷封装工具,快速将Python打包为EXE并添加CUDA、NoAVX等支持。
Stars: ✭ 308 (+1300%)
Mutual labels:  paddlepaddle
style-vae
Implementation of VAE and Style-GAN Architecture Achieving State of the Art Reconstruction
Stars: ✭ 25 (+13.64%)
Mutual labels:  perceptual-losses
PASSL
PASSL包含 SimCLR,MoCo v1/v2,BYOL,CLIP,PixPro,BEiT,MAE等图像自监督算法以及 Vision Transformer,DEiT,Swin Transformer,CvT,T2T-ViT,MLP-Mixer,XCiT,ConvNeXt,PVTv2 等基础视觉算法
Stars: ✭ 134 (+509.09%)
Mutual labels:  paddle
finetuner
Finetuning any DNN for better embedding on neural search tasks
Stars: ✭ 442 (+1909.09%)
Mutual labels:  paddlepaddle
stylegan-encoder
StyleGAN Encoder - converts real images to latent space
Stars: ✭ 694 (+3054.55%)
Mutual labels:  perceptual-losses
Visualdl
Deep Learning Visualization Toolkit(『飞桨』深度学习可视化工具 )
Stars: ✭ 4,258 (+19254.55%)
Mutual labels:  paddlepaddle
Dali
A GPU-accelerated library containing highly optimized building blocks and an execution engine for data processing to accelerate deep learning training and inference applications.
Stars: ✭ 3,624 (+16372.73%)
Mutual labels:  paddle
CPCE-3D
Low-dose CT via Transfer Learning from a 2D Trained Network, In IEEE TMI 2018
Stars: ✭ 40 (+81.82%)
Mutual labels:  perceptual-losses
docs
Documentations for PaddlePaddle
Stars: ✭ 124 (+463.64%)
Mutual labels:  paddlepaddle
Paddle
PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
Stars: ✭ 17,232 (+78227.27%)
Mutual labels:  paddlepaddle
Paddle-Image-Models
A PaddlePaddle version image model zoo.
Stars: ✭ 131 (+495.45%)
Mutual labels:  paddlepaddle
mSRGAN-A-GAN-for-single-image-super-resolution-on-high-content-screening-microscopy-images.
Generative Adversarial Network for single image super-resolution in high content screening microscopy images
Stars: ✭ 52 (+136.36%)
Mutual labels:  perceptual-losses
Netron
Visualizer for neural network, deep learning, and machine learning models
Stars: ✭ 17,193 (+78050%)
Mutual labels:  paddle

Perceptual Similarity Metric on PaddlePaddle

This repository is converted from its PyTorch version richzhang/PerceptualSimilarity.

Follow the command lines to install it use pip:

pip install paddle-lpips

or install it from source:

git clone https://github.com/AgentMaker/Paddle-PerceptualSimilarity.git
cd Paddle-PerceptualSimilarity
pip install .

Use it like the original PyTorch package but replace import method like this:

import paddle_lpips as lpips

The following is the original README.md of the original repository.

Perceptual Similarity Metric and Dataset [Project Page]

The Unreasonable Effectiveness of Deep Features as a Perceptual Metric
Richard Zhang, Phillip Isola, Alexei A. Efros, Eli Shechtman, Oliver Wang. In CVPR, 2018.

Quick start

Run pip install lpips. The following Python code is all you need.

import lpips
loss_fn_alex = lpips.LPIPS(net='alex') # best forward scores
loss_fn_vgg = lpips.LPIPS(net='vgg') # closer to "traditional" perceptual loss, when used for optimization

import torch
img0 = torch.zeros(1,3,64,64) # image should be RGB, IMPORTANT: normalized to [-1,1]
img1 = torch.zeros(1,3,64,64)
d = loss_fn_alex(img0, img1)

More thorough information about variants is below. This repository contains our perceptual metric (LPIPS) and dataset (BAPPS). It can also be used as a "perceptual loss". This uses PyTorch; a Tensorflow alternative is here.

Table of Contents

  1. Learned Perceptual Image Patch Similarity (LPIPS) metric
    a. Basic Usage If you just want to run the metric through command line, this is all you need.
    b. "Perceptual Loss" usage
    c. About the metric
  2. Berkeley-Adobe Perceptual Patch Similarity (BAPPS) dataset
    a. Download
    b. Evaluation
    c. About the dataset
    d. Train the metric using the dataset

(0) Dependencies/Setup

Installation

pip install -r requirements.txt
  • Clone this repo:
git clone https://github.com/richzhang/PerceptualSimilarity
cd PerceptualSimilarity

(1) Learned Perceptual Image Patch Similarity (LPIPS) metric

Evaluate the distance between image patches. Higher means further/more different. Lower means more similar.

(A) Basic Usage

(A.I) Line commands

Example scripts to take the distance between 2 specific images, all corresponding pairs of images in 2 directories, or all pairs of images within a directory:

python lpips_2imgs.py -p0 imgs/ex_ref.png -p1 imgs/ex_p0.png
python lpips_2dirs.py -d0 imgs/ex_dir0 -d1 imgs/ex_dir1 -o imgs/example_dists.txt
python lpips_1dir_allpairs.py -d imgs/ex_dir_pair -o imgs/example_dists_pair.txt

(A.II) Python code

File test_network.py shows example usage. This snippet is all you really need.

import lpips
loss_fn = lpips.LPIPS(net='alex')
d = loss_fn.forward(im0,im1)

Variables im0, im1 is a PyTorch Tensor/Variable with shape Nx3xHxW (N patches of size HxW, RGB images scaled in [-1,+1]). This returns d, a length N Tensor/Variable.

Run python test_network.py to take the distance between example reference image ex_ref.png to distorted images ex_p0.png and ex_p1.png. Before running it - which do you think should be closer?

Some Options By default in model.initialize:

  • By default, net='alex'. Network alex is fastest, performs the best (as a forward metric), and is the default. For backpropping, net='vgg' loss is closer to the traditional "perceptual loss".
  • By default, lpips=True. This adds a linear calibration on top of intermediate features in the net. Set this to lpips=False to equally weight all the features.

(B) Backpropping through the metric

File lpips_loss.py shows how to iteratively optimize using the metric. Run python lpips_loss.py for a demo. The code can also be used to implement vanilla VGG loss, without our learned weights.

(C) About the metric

Higher means further/more different. Lower means more similar.

We found that deep network activations work surprisingly well as a perceptual similarity metric. This was true across network architectures (SqueezeNet [2.8 MB], AlexNet [9.1 MB], and VGG [58.9 MB] provided similar scores) and supervisory signals (unsupervised, self-supervised, and supervised all perform strongly). We slightly improved scores by linearly "calibrating" networks - adding a linear layer on top of off-the-shelf classification networks. We provide 3 variants, using linear layers on top of the SqueezeNet, AlexNet (default), and VGG networks.

If you use LPIPS in your publication, please specify which version you are using. The current version is 0.1. You can set version='0.0' for the initial release.

(2) Berkeley Adobe Perceptual Patch Similarity (BAPPS) dataset

(A) Downloading the dataset

Run bash ./scripts/download_dataset.sh to download and unzip the dataset into directory ./dataset. It takes [6.6 GB] total. Alternatively, run bash ./scripts/get_dataset_valonly.sh to only download the validation set [1.3 GB].

  • 2AFC train [5.3 GB]
  • 2AFC val [1.1 GB]
  • JND val [0.2 GB]

(B) Evaluating a perceptual similarity metric on a dataset

Script test_dataset_model.py evaluates a perceptual model on a subset of the dataset.

Dataset flags

  • --dataset_mode: 2afc or jnd, which type of perceptual judgment to evaluate
  • --datasets: list the datasets to evaluate
    • if --dataset_mode 2afc: choices are [train/traditional, train/cnn, val/traditional, val/cnn, val/superres, val/deblur, val/color, val/frameinterp]
    • if --dataset_mode jnd: choices are [val/traditional, val/cnn]

Perceptual similarity model flags

  • --model: perceptual similarity model to use
    • lpips for our LPIPS learned similarity model (linear network on top of internal activations of pretrained network)
    • baseline for a classification network (uncalibrated with all layers averaged)
    • l2 for Euclidean distance
    • ssim for Structured Similarity Image Metric
  • --net: [squeeze,alex,vgg] for the net-lin and net models; ignored for l2 and ssim models
  • --colorspace: choices are [Lab,RGB], used for the l2 and ssim models; ignored for net-lin and net models

Misc flags

  • --batch_size: evaluation batch size (will default to 1)

An example usage is as follows: python ./test_dataset_model.py --dataset_mode 2afc --datasets val/traditional val/cnn --model lpips --net alex --batch_size 50. This would evaluate our model on the "traditional" and "cnn" validation datasets.

(C) About the dataset

The dataset contains two types of perceptual judgements: Two Alternative Forced Choice (2AFC) and Just Noticeable Differences (JND).

(1) 2AFC Evaluators were given a patch triplet (1 reference + 2 distorted). They were asked to select which of the distorted was "closer" to the reference.

Training sets contain 2 judgments/triplet.

  • train/traditional [56.6k triplets]
  • train/cnn [38.1k triplets]
  • train/mix [56.6k triplets]

Validation sets contain 5 judgments/triplet.

  • val/traditional [4.7k triplets]
  • val/cnn [4.7k triplets]
  • val/superres [10.9k triplets]
  • val/deblur [9.4k triplets]
  • val/color [4.7k triplets]
  • val/frameinterp [1.9k triplets]

Each 2AFC subdirectory contains the following folders:

  • ref: original reference patches
  • p0,p1: two distorted patches
  • judge: human judgments - 0 if all preferred p0, 1 if all humans preferred p1

(2) JND Evaluators were presented with two patches - a reference and a distorted - for a limited time. They were asked if the patches were the same (identically) or different.

Each set contains 3 human evaluations/example.

  • val/traditional [4.8k pairs]
  • val/cnn [4.8k pairs]

Each JND subdirectory contains the following folders:

  • p0,p1: two patches
  • same: human judgments: 0 if all humans thought patches were different, 1 if all humans thought patches were same

(D) Using the dataset to train the metric

See script train_test_metric.sh for an example of training and testing the metric. The script will train a model on the full training set for 10 epochs, and then test the learned metric on all of the validation sets. The numbers should roughly match the Alex - lin row in Table 5 in the paper. The code supports training a linear layer on top of an existing representation. Training will add a subdirectory in the checkpoints directory.

You can also train "scratch" and "tune" versions by running train_test_metric_scratch.sh and train_test_metric_tune.sh, respectively.

Citation

If you find this repository useful for your research, please use the following.

@inproceedings{zhang2018perceptual,
  title={The Unreasonable Effectiveness of Deep Features as a Perceptual Metric},
  author={Zhang, Richard and Isola, Phillip and Efros, Alexei A and Shechtman, Eli and Wang, Oliver},
  booktitle={CVPR},
  year={2018}
}

Acknowledgements

This repository borrows partially from the pytorch-CycleGAN-and-pix2pix repository. The average precision (AP) code is borrowed from the py-faster-rcnn repository. Angjoo Kanazawa, Connelly Barnes, Gaurav Mittal, wilhelmhb, Filippo Mameli, SuperShinyEyes, Minyoung Huh helped to improve the codebase.

Contact us

Email : [email protected]
QQ Group : 1005109853

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].