Roman Suvorov, Elizaveta Logacheva, Anton Mashikhin, Anastasia Remizova, Arsenii Ashukha, Aleksei Silvestrov, Naejin Kong, Harshith Goka, Kiwoong Park, Victor Lempitsky.
라마는 훈련 중 (256x256)보다 훨씬 높은 해상도 (~ 2k❗️)에 놀랍게 잘 일반화되며, 예를 들어 주기적 구조의 완료와 같은 도전적인 시나리오에서도 우수한 성능을 달성합니다.
[프로젝트 페이지] [ARXIV] [보충] [BIBTEX] [CASUAL GAN PAPERS 요약]
Google Colab에서 사용해보십시오
(문제를 만들어 논문을 공유하십시오)
(문제를 만들어 앱/구현/데모를 자유롭게 공유하십시오)
레포를 복제하십시오 : git clone https://github.com/advimman/lama.git
환경에는 세 가지 옵션이 있습니다.
Python Virtualenv :
virtualenv inpenv --python=/usr/bin/python3
source inpenv/bin/activate
pip install torch==1.8.0 torchvision==0.9.0
cd lama
pip install -r requirements.txt
콘다
% Install conda for Linux, for other OS download miniconda at https://docs.conda.io/en/latest/miniconda.html
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh -b -p $HOME/miniconda
$HOME/miniconda/bin/conda init bash
cd lama
conda env create -f conda_env.yml
conda activate lama
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch -y
pip install pytorch-lightning==1.2.9
Docker : 조치가 필요하지 않습니까?.
달리다
cd lama
export TORCH_HOME=$(pwd) && export PYTHONPATH=$(pwd)
1. 미리 훈련 된 모델을 다운로드하십시오
최고의 모델 (Place2, Place Challenge) :
curl -LJO https://huggingface.co/smartywu/big-lama/resolve/main/big-lama.zip
unzip big-lama.zip
모든 모델 (Places & Celeba-HQ) :
download [https://drive.google.com/drive/folders/1B2x7eQDgecTL0oh3LSIBDGj0fTxs6Ips?usp=drive_link]
unzip lama-models.zip
2. 이미지와 마스크를 준비하십시오
테스트 이미지 다운로드 :
unzip LaMa_test_images.zip
image1_mask001.png
image1.png
image2_mask001.png
image2.png
configs/prediction/default.yaml 에서 image_suffix , 예를 들어 .png 또는 .jpg 또는 _input.jpg 지정하십시오.3. 예측
호스트 머신에서 :
python3 bin/predict.py model.path=$(pwd)/big-lama indir=$(pwd)/LaMa_test_images outdir=$(pwd)/output
또는 Docker에서
다음 명령은 Docker Hub에서 Docker Image를 가져 와서 예측 스크립트를 실행합니다.
bash docker/2_predict.sh $(pwd)/big-lama $(pwd)/LaMa_test_images $(pwd)/output device=cpu
Docker Cuda :
bash docker/2_predict_with_gpu.sh $(pwd)/big-lama $(pwd)/LaMa_test_images $(pwd)/output
4. 개선을 예측하십시오
호스트 머신에서 :
python3 bin/predict.py refine=True model.path=$(pwd)/big-lama indir=$(pwd)/LaMa_test_images outdir=$(pwd)/output
실행하십시오 :
cd lama
export TORCH_HOME=$(pwd) && export PYTHONPATH=$(pwd)
그런 다음 지각 손실 에 대한 모델을 다운로드하십시오.
mkdir -p ade20k/ade20k-resnet50dilated-ppm_deepsup/
wget -P ade20k/ade20k-resnet50dilated-ppm_deepsup/ http://sceneparsing.csail.mit.edu/model/pytorch/ade20k-resnet50dilated-ppm_deepsup/encoder_epoch_20.pth
호스트 머신에서 :
# Download data from http://places2.csail.mit.edu/download.html
# Places365-Standard: Train(105GB)/Test(19GB)/Val(2.1GB) from High-resolution images section
wget http://data.csail.mit.edu/places/places365/train_large_places365standard.tar
wget http://data.csail.mit.edu/places/places365/val_large.tar
wget http://data.csail.mit.edu/places/places365/test_large.tar
# Unpack train/test/val data and create .yaml config for it
bash fetch_data/places_standard_train_prepare.sh
bash fetch_data/places_standard_test_val_prepare.sh
# Sample images for test and viz at the end of epoch
bash fetch_data/places_standard_test_val_sample.sh
bash fetch_data/places_standard_test_val_gen_masks.sh
# Run training
python3 bin/train.py -cn lama-fourier location=places_standard
# To evaluate trained model and report metrics as in our paper
# we need to sample previously unseen 30k images and generate masks for them
bash fetch_data/places_standard_evaluation_prepare_data.sh
# Infer model on thick/thin/medium masks in 256 and 512 and run evaluation
# like this:
python3 bin/predict.py
model.path=$(pwd)/experiments/<user>_<date:time>_lama-fourier_/
indir=$(pwd)/places_standard_dataset/evaluation/random_thick_512/
outdir=$(pwd)/inference/random_thick_512 model.checkpoint=last.ckpt
python3 bin/evaluate_predicts.py
$(pwd)/configs/eval2_gpu.yaml
$(pwd)/places_standard_dataset/evaluation/random_thick_512/
$(pwd)/inference/random_thick_512
$(pwd)/inference/random_thick_512_metrics.csv
Docker : Todo
호스트 머신에서 :
# Make shure you are in lama folder
cd lama
export TORCH_HOME=$(pwd) && export PYTHONPATH=$(pwd)
# Download CelebA-HQ dataset
# Download data256x256.zip from https://drive.google.com/drive/folders/11Vz0fqHS2rXDb5pprgTjpD7S2BAJhi1P
# unzip & split into train/test/visualization & create config for it
bash fetch_data/celebahq_dataset_prepare.sh
# generate masks for test and visual_test at the end of epoch
bash fetch_data/celebahq_gen_masks.sh
# Run training
python3 bin/train.py -cn lama-fourier-celeba data.batch_size=10
# Infer model on thick/thin/medium masks in 256 and run evaluation
# like this:
python3 bin/predict.py
model.path=$(pwd)/experiments/<user>_<date:time>_lama-fourier-celeba_/
indir=$(pwd)/celeba-hq-dataset/visual_test_256/random_thick_256/
outdir=$(pwd)/inference/celeba_random_thick_256 model.checkpoint=last.ckpt
Docker : Todo
호스트 머신에서 :
# This script downloads multiple .tar files in parallel and unpacks them
# Places365-Challenge: Train(476GB) from High-resolution images (to train Big-Lama)
bash places_challenge_train_download.sh
TODO: prepare
TODO: train
TODO: eval
Docker : Todo
다음 단계 중 하나에 갇힌 경우 Celebahq 섹션에서 데이터 준비 및 마스크 생성에 대한 Bash 스크립트를 확인하십시오.
호스트 머신에서 :
# Make shure you are in lama folder
cd lama
export TORCH_HOME=$(pwd) && export PYTHONPATH=$(pwd)
# You need to prepare following image folders:
$ ls my_dataset
train
val_source # 2000 or more images
visual_test_source # 100 or more images
eval_source # 2000 or more images
# LaMa generates random masks for the train data on the flight,
# but needs fixed masks for test and visual_test for consistency of evaluation.
# Suppose, we want to evaluate and pick best models
# on 512x512 val dataset with thick/thin/medium masks
# And your images have .jpg extention:
python3 bin/gen_mask_dataset.py
$(pwd)/configs/data_gen/random_<size>_512.yaml # thick, thin, medium
my_dataset/val_source/
my_dataset/val/random_<size>_512.yaml # thick, thin, medium
--ext jpg
# So the mask generator will:
# 1. resize and crop val images and save them as .png
# 2. generate masks
ls my_dataset/val/random_medium_512/
image1_crop000_mask000.png
image1_crop000.png
image2_crop000_mask000.png
image2_crop000.png
...
# Generate thick, thin, medium masks for visual_test folder:
python3 bin/gen_mask_dataset.py
$(pwd)/configs/data_gen/random_<size>_512.yaml #thick, thin, medium
my_dataset/visual_test_source/
my_dataset/visual_test/random_<size>_512/ #thick, thin, medium
--ext jpg
ls my_dataset/visual_test/random_thick_512/
image1_crop000_mask000.png
image1_crop000.png
image2_crop000_mask000.png
image2_crop000.png
...
# Same process for eval_source image folder:
python3 bin/gen_mask_dataset.py
$(pwd)/configs/data_gen/random_<size>_512.yaml #thick, thin, medium
my_dataset/eval_source/
my_dataset/eval/random_<size>_512/ #thick, thin, medium
--ext jpg
# Generate location config file which locate these folders:
touch my_dataset.yaml
echo "data_root_dir: $(pwd)/my_dataset/" >> my_dataset.yaml
echo "out_root_dir: $(pwd)/experiments/" >> my_dataset.yaml
echo "tb_dir: $(pwd)/tb_logs/" >> my_dataset.yaml
mv my_dataset.yaml ${PWD}/configs/training/location/
# Check data config for consistency with my_dataset folder structure:
$ cat ${PWD}/configs/training/data/abl-04-256-mh-dist
...
train:
indir: ${location.data_root_dir}/train
...
val:
indir: ${location.data_root_dir}/val
img_suffix: .png
visual_test:
indir: ${location.data_root_dir}/visual_test
img_suffix: .png
# Run training
python3 bin/train.py -cn lama-fourier location=my_dataset data.batch_size=10
# Evaluation: LaMa training procedure picks best few models according to
# scores on my_dataset/val/
# To evaluate one of your best models (i.e. at epoch=32)
# on previously unseen my_dataset/eval do the following
# for thin, thick and medium:
# infer:
python3 bin/predict.py
model.path=$(pwd)/experiments/<user>_<date:time>_lama-fourier_/
indir=$(pwd)/my_dataset/eval/random_<size>_512/
outdir=$(pwd)/inference/my_dataset/random_<size>_512
model.checkpoint=epoch32.ckpt
# metrics calculation:
python3 bin/evaluate_predicts.py
$(pwd)/configs/eval2_gpu.yaml
$(pwd)/my_dataset/eval/random_<size>_512/
$(pwd)/inference/my_dataset/random_<size>_512
$(pwd)/inference/my_dataset/random_<size>_512_metrics.csv
또는 Docker에서 :
TODO: train
TODO: eval
다음 명령은 임의의 마스크를 생성하는 스크립트를 실행합니다.
bash docker/1_generate_masks_from_raw_images.sh
configs/data_gen/random_medium_512.yaml
/directory_with_input_images
/directory_where_to_store_images_and_masks
--ext png
테스트 데이터 생성 명령은 이미지를 형식으로 저장하며 예측에 적합합니다.
아래 표는 논문에서 다른 테스트 세트를 생성하는 데 사용한 구성을 설명합니다. 임의의 씨앗을 고치지 않으므로 결과는 매번 약간 다릅니다.
| 장소 512x512 | Celeba 256x256 | |
|---|---|---|
| 좁은 | random_thin_512.yaml | random_thin_256.yaml |
| 중간 | random_medium_512.yaml | random_medium_256.yaml |
| 넓은 | random_thick_512.yaml | random_thick_256.yaml |
configs/data_gen 의 다른 구성으로 구성 경로 (Argument #1)를 자유롭게 변경하거나 구성 파일 자체를 조정하십시오.
또한 다음과 같은 구성에서 매개 변수를 재정의 할 수 있습니다.
python3 bin/train.py -cn <config> data.batch_size=10 run_title=my-title
.yaml 파일 확장자가 생략되는 곳
종이의 모델 구성 (교육 명령으로의 비열) :
* big-lama
* big-lama-regular
* lama-fourier
* lama-regular
* lama_small_train_masks
구성/교육/폴더에 앉아 있습니다
TODO
이 코드가 도움이된다면 다음을 고려하십시오.
@article{suvorov2021resolution,
title={Resolution-robust Large Mask Inpainting with Fourier Convolutions},
author={Suvorov, Roman and Logacheva, Elizaveta and Mashikhin, Anton and Remizova, Anastasia and Ashukha, Arsenii and Silvestrov, Aleksei and Kong, Naejin and Goka, Harshith and Park, Kiwoong and Lempitsky, Victor},
journal={arXiv preprint arXiv:2109.07161},
year={2021}
}