1 Introduction

September 28, 2021 · View on GitHub

论文复现:Only a Matter of Style: Age Transformation Using a Style-Based Regression Model


English|简体中文

1 Introduction


This protest reproduces SAM based on paddlepaddle framework.SAM is an image-to-imagetranslation method that learns to directly encode real facial images into the latent space of a pre-trained unconditional GAN subject to a given aging shift.

Paper

  • [1] Y Alaluf, Patashnik O , Cohen-Or D . Only a Matter of Style: Age Transformation Using a Style-Based Regression Model[J]. 2021.

Reference project

Project on Ai Studio

  • notebook

https://aistudio.baidu.com/aistudio/projectdetail/2331297

2 Result

  • The current presented is the result of the model that is saved 24,000 steps. According to the author's results, the results are running 60000 steps. The picture from left to right is: Enter the picture, the model is 0 years old, 10 years old, 20 years old, 30 Years, 40 years old, 60 years old, 70 years old, 80 years old, 90 years old, 100 years old.

Visual comparison

模型图片
Pytorch 1
Paddle1
Pytorch1
Paddle1
Pytorch1
Paddle1

3 Datasets

  • Training: FFHQ-1024. saved in SAM/data/FFHQ/.
  • Testing:CelebA-HQ.saved inSAM/data/CelebA_test/.

4 Environment

Hardware:GPU、CPU

Framework:PaddlePaddle >=2.0.0

5 Pretrained models

Pretrained models saved inpretrained_models/.

Pretrained modelsDescription
FFHQ StyleGAN(stylegan2-ffhq-config-f.pdparams)StyleGAN trained with the FFHQ dataset fromrosinality ,output size:1024x1024
IR-SE50 Model(model_ir_se50.pdparams)IR_SE model (TreB1eN)trained for computering ID loss.
CurricularFace Backbone(CurricularFace_Backbone.paparams)Pretrained CurricularFace model(HuangYG123)evaled Similarity
AlexNet(alexnet.pdparams和lin_alex.pdparams)computered lpips loss
StyleGAN Inversion(psp_ffhq_inverse.pdparams)pSp trained with the FFHQ dataset for StyleGAN inversion.

Baidu driver:https://pan.baidu.com/s/1G-Ffs8-y93R0ZlD9mEU6Eg password:m3nb

6 Quick start

# clone this repo
git clone [https://github.com/771979972/paddle-SAM.git]
cd work

Inference

python SAM/scripts/inference_side_by_side.py 
--exp_dir=exp/test 
--checkpoint_path=SAM/pretrained_models/sam_ffhq_aging.pdparams 
--data_path=SAM/data/CelebA_test 
--test_batch_size=4 
--test_workers=0 
--target_age=0,10,20,30,40,50,60,70,80,90,100

Configuration Environment

!pip install --upgrade matplotlib
python SAM/scripts/compile_ranger.py

Train

python SAM/scripts/train.py /
--dataset_type=ffhq_encode /
--exp_dir=exp/test /
--workers=0 /
--batch_size=8/
--test_batch_size=8 /
--test_workers=0 /
--val_interval=2500 /
--save_interval=5000 /
--encoder_type=GradualStyleEncoder/
--start_from_latent_avg /
--lpips_lambda=0.8 \--l2_lambda=1 /
--id_lambda=0.1 /
--optim_name=ranger

Others

LPIPS

python SAM/scripts/calc_losses_on_images.py /
--mode lpips /
--data_path=SAM/inference/inference_results /
--gt_path=SAM/data/CelebA_test/

MSE

python SAM/scripts/calc_losses_on_images.py /
--mode l2 /
--data_path=SAM/inference/inference_results /
--gt_path=SAM/data/CelebA_test/

Similarity

python SAM/scripts/calc_id_loss_parallel.py /
--data_path=SAM/inference/inference_results /
--gt_path=SAM/data/CelebA_test/

7 Code structure

Structure

├─config          # 配置
├─data            #数据集加载
   ├─CelebA_test  # 测试数据图像
├─models          # 模型
    ├─encoders    # 编码器
    ├─loss        # 损失函数
    ├─utils       # 编译算子
├─scripts         #算法执行
    trian         #训练
    inference     #测试
    inference_side_by_side    #测试
    reference_guided_inference    #测试
├─utils           # 工具代码
│  README.md      #英文readme
│  README_cn.md   #中文readme

Parameter description

ParameterDefault
configNone
dataset_typeffhq_aging
exp_direxp/test
workers0
test_workers0
batch_size6
test_batch_size6
start_from_encoded_w_plusstore-true
use_weighted_id_lossstore-true
id_lambda0.1
lpips_lambda0.1
lpips_lambda_aging0.1
lpips_lambda_crop0.6
l2_lambda0.25
l2_lambda_aging0,25
l2_lambda_crop1
w_norm_lambda0,005
aging_lambda5
cycle_lambda1
input_nc4
target_ageuniform_random

8 Model information

The overall information of the model is as follows:

InformationDescriptions
VersionPaddle 2.1.2
ApplicationImage Generation
HardwareGPU / CPU

License

#encoding=utf8
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#     http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.