いろいろな画像系機械学習機能が手軽に使える　mmeditingの使いかた

MMEditingは、
**・Inpainting**
**・Matting
・SuperResolution
・フレーム補完
・画像変換**
が使えるツールボックス。

使用可能なモデルはいっぱいある。

>### Supported algorithms:
>**Inpainting**
 Global&Local (ToG'2017)
 DeepFillv1 (CVPR'2018)
 PConv (ECCV'2018)
 DeepFillv2 (CVPR'2019)
 AOT-GAN (TVCG'2021)
**Matting**
 DIM (CVPR'2017)
 IndexNet (ICCV'2019)
 GCA (AAAI'2020)
**Image-Super-Resolution**
 SRCNN (TPAMI'2015)
 SRResNet&SRGAN (CVPR'2016)
 EDSR (CVPR'2017)
 ESRGAN (ECCV'2018)
 RDN (CVPR'2018)
 DIC (CVPR'2020)
 TTSR (CVPR'2020)
 GLEAN (CVPR'2021)
 LIIF (CVPR'2021)
**Video-Super-Resolution**
 EDVR (CVPR'2019)
 TOF (IJCV'2019)
 TDAN (CVPR'2020)
 BasicVSR (CVPR'2021)
 IconVSR (CVPR'2021)
 BasicVSR++ (CVPR'2022)
 RealBasicVSR (CVPR'2022)
**Generation**
 CycleGAN (ICCV'2017)
 pix2pix (CVPR'2017)
**Video Interpolation**
 TOFlow (IJCV'2019)
 CAIN (AAAI'2020)
 FLAVR (CVPR'2021)

![158984079-c4754015-c1f6-48c5-ac46-62e79448c372.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/41f6f8af-a31a-e67a-5bd7-655bb1289e83.jpeg)
↑公式リポジトリより

https://github.com/open-mmlab/mmediting

# 使いかた

## インストール

```bash
pip3 install openmim
mim install mmcv-full
git clone https://github.com/open-mmlab/mmediting.git
cd mmediting
pip3 install -e .
```

## 推論

それぞれのタスクのデモスクリプトを実行する。
引数に、タスクのコンフィグファイルパスとチェックポイントパス、入出力パスなどを指定する。

### Inpainting

```bash
python demo/inpainting_demo.py \
    configs/inpainting/global_local/gl_256x256_8x12_celeba.py \ # config
    https://download.openmmlab.com/mmediting/inpainting/global_local/gl_256x256_8x12_celeba_20200619-5af0493f.pth \ # checkpoint
    tests/data/image/celeba_test.png \ # input
    tests/data/image/bbox_mask.png \ # mask
    tests/data/pred/inpainting_celeba.png # result
```

input / mask / result

![celeba_test.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/28475a7d-382f-236e-6752-4cc24b724080.png)![bbox_mask.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/7592ad8b-4261-c360-bd26-dbfe703ad805.png)![inpainting_celeba.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/80841d7f-1665-1563-96a6-81836ccae7a8.png)

### Matting

```bash
python demo/matting_demo.py \
    configs/mattors/dim/dim_stage3_v16_pln_1x1_1000k_comp1k.py \ # config
    https://download.openmmlab.com/mmediting/mattors/dim/dim_stage3_v16_pln_1x1_1000k_comp1k_SAD-50.6_20200609_111851-647f24b6.pth \ # checkpoint
    tests/data/merged/GT05.jpg \ # input
    tests/data/trimap/GT05.png \ # trimap
    tests/data/pred/GT05.png # result
```

input / trimap / result

<img src = https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/97f1d799-cafe-89ef-dda8-caf092e49a02.jpeg width= 250> <img src = https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/39ec7659-bc2d-c709-0273-e3b8260790e9.png width= 250> <img src = https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/8c706f44-aa80-f22d-e89d-d3c2a003868d.png width= 250>

### SuperResolution

```shell
python demo/restoration_demo.py \
    configs/restorers/esrgan/esrgan_x4c64b23g32_g1_400k_div2k.py \ # config
    https://download.openmmlab.com/mmediting/restorers/esrgan/esrgan_x4c64b23g32_1x16_400k_div2k_20200508-f8ccaf3b.pth \ # checkpoint
    tests/data/lq/baboon_x4.png \ # input
    demo/demo_out_baboon.png # result
```

input / result

<img src = https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/f863a197-5040-3902-6ae7-39df1696d616.png width=300>
<img src = https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/452c7e61-c108-c085-7327-f4784a7d6985.png width=300>

### Video Super Resolution

```bash
python demo/restoration_video_demo.py \
    ./configs/restorers/edvr/edvrm_wotsa_x4_g8_600k_reds.py \
    https://download.openmmlab.com/mmediting/restorers/edvr/edvrm_wotsa_x4_8x4_600k_reds_20200522-0570e567.pth \
    tests/data/vimeo90k/00001/0266/ \
    ./output \
    --window-size=5
```

<img src = https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/6f43efa2-38a4-96de-3bf7-0d3945f4cff9.gif width=300> <img src = https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/91c08d1e-52be-370e-a767-7067ba445e72.gif width=300>

### フレーム補完

```bash
python demo/video_interpolation_demo.py \
    configs/video_interpolators/cain/cain_b5_g1b32_vimeo90k_triplet.py \
    https://download.openmmlab.com/mmediting/video_interpolators/cain/cain_b5_g1b32_vimeo90k_triplet_20220530-3520b00c.pth    tests/data/test_inference.mp4 \
    tests/data/test_inference_vfi_out.mp4 \
    --fps-multiplier 2.0 \
    --device 0
```

<img src = https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/91c08d1e-52be-370e-a767-7067ba445e72.gif width=300> <img src = https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/6cb74f7a-c798-70dc-b200-bddcdae0b716.gif width=300>

### 画像生成

```shell
python demo/generation_demo.py \
    configs/synthesizers/pix2pix/pix2pix_vanilla_unet_bn_1x1_80k_facades.py \
    https://download.openmmlab.com/mmediting/synthesizers/pix2pix/pix2pix_facades/pix2pix_vanilla_unet_bn_1x1_80k_facades_20200524-6206de67.pth \
    tests/data/paired/test/3.jpg \
    demo/demo_out.jpg
```

input / result / ground truth

![demo_out.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/531472be-666f-366e-70eb-7031f85dfd52.jpeg)


🐣
****
フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

機械学習、ARアプリ（Web/iOS）を作っています。
機械学習／AR関連の情報を発信しています。

[Twitter](https://twitter.com/JackdeS11)
[Medium](https://medium.com/@rockyshikoku)
[GitHub](https://github.com/john-rocky)