DIS: Highly Accurate Dichotomous Image Segmentation やーる（Windows10、Python3.9）

# はじめに
画像セグメンテーションのDISやっていきまーす

# 開発環境
- Windows10 PC
- Python 3.9
- Anaconda

# 導入

1．[DIS](https://github.com/xuebinqin/DIS)をクローンします

~~~
conda activate py39
git clone https://github.com/xuebinqin/DIS.git
cd DIS/IS-Net
~~~

2．requirements.txtについては後で書くかもしれない（U^2Netが動いていれば動くかも）

3．[isnet.pth](https://drive.google.com/file/d/1KyMpRjewZdyYfxHPYcd-ZbanIXtin0Sn/view?usp=sharing)をダウンロードし、saved_models/IS-Netに置きます

4．推論のためにtrain_valid_inference_main.pyを修正します

664行目
~~~
valid_datasets = [dataset_vd] # dataset_vd, dataset_te1, dataset_te2, dataset_te3, dataset_te4] # and hypar["mode"] = "valid" for inference,
~~~
↓
~~~
valid_datasets = [dataset_demo]
~~~

670行目
~~~
hypar["mode"] = "train"
~~~
↓
~~~
hypar["mode"] = "valid"
~~~

5．your-dataset/imにテストデータを置きます

655行目
~~~
dataset_demo = {"name": "your-dataset",
                "im_dir": "../your-dataset/im",
                "gt_dir": "",
                "im_ext": ".jpg",
                "gt_ext": "",
                "cache_dir":"../your-dataset/cache"}
~~~

6．結果はyour-resultsに出力されます

684行目
~~~
hypar["valid_out_dir"] = "../your-results/"##"../DIS5K-Results-test" ## output inferenced segmentation maps into this fold
~~~

# 実行

~~~
python train_valid_inference_main.py
~~~

U^2Netのテストデータを持ってきました。2枚目の処理でGPUが足りないと怒られました。。

a:入力画像
b:DIS
c:U^2Net

|a|b|c|
|:--|:--|:--|
|![0002-01.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/2afca1ea-be44-8f47-1832-3c12d68d1ef6.jpeg)|![0002-01.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/bafd232f-21a2-8f9e-2e64-0b6d598b2f1e.png)|![0002-01.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/c05e1a1e-eee9-0779-aa14-16ee911a7732.png)|
|![0003.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/ae625dc4-4fc5-6d1a-06ec-cda19bc25bc0.jpeg)|![0003.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/9e1409c3-a3d8-9ed4-56d9-fc6d1fbe427f.png)|![0003.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/5d0529b3-47b0-bc0b-24d6-91a363262b9a.png)|
|![bike.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/896727d8-c8e8-ed2f-5319-a6de07a081a7.jpeg)|![bike.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/c412539f-a773-6223-396a-f53cfa26658f.png)|![bike.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/07dccd35-c124-27cd-3f70-d2d00b096d66.png)|
|![boat.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/9270eba4-5b1a-cf9a-7540-4ac62c16c6c7.jpeg)|![boat.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/04211be5-d74e-8da9-0730-96cabee977b4.png)|![boat.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/e7ec8ac9-18dd-7006-8788-7c43312fc85a.png)|
|![horse.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/da51e4dc-6406-98d3-32dd-73fdd4789088.jpeg)|![horse.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/a8e3db04-249c-e2df-f214-dfddf0ef25f3.png)|![horse.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/8c1af7a6-ceb4-d458-c234-eecd1bd16e02.png)|
|![lamp2_meitu_1.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/8e431761-5ae7-9c2e-1565-42fd0a5a6ad6.jpeg)|![lamp2_meitu_1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/d4fc54f4-c8f3-84e9-db02-810295118135.png)|![lamp2_meitu_1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/ae223083-e8d1-f27d-cf80-b625374f9947.png)|
|![long.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/88767b7d-6171-6763-e7fa-b6b39134886e.jpeg)|![long.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/65bbef34-9b83-cb77-c462-7c8ec0b4d98e.png)|![long.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/2f1937c8-7e52-c799-43fe-859fa561f1d4.png)|
|![rifle1.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/d6c46a78-d000-dc1c-8e13-2021b559d86c.jpeg)|![rifle1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/86a8a5a5-fa84-57f9-54a8-202088191528.png)|![rifle1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/32f6d9f2-5a97-89b5-776b-f3504aa03403.png)|
|![sailboat3.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/4a06d278-3465-dded-6618-15930997c12b.jpeg)|![sailboat3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/ce4375f5-bb3a-5459-9345-759b2bbec49c.png)|![sailboat3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/a9cb2604-5ff3-dc48-278e-aa85e45750fc.png)|
<!--
|![girl.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/5aa62cca-208b-2112-c5e0-298083a5c11c.png)||![girl.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/e1e5a430-700c-2caa-1cad-60b3b350035e.png)|
|![hockey.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/e87b616d-525c-d0cb-fa40-553029d8edb5.png)||![hockey.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/dbf5a2ca-bb7e-2448-b853-a01f6091e2a8.png)|
|![im_01.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/47610b76-15ea-c6cb-7042-8e41a6d7a94b.png)||![im_01.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/70268c89-c14d-241c-d5ea-c5d8f9bdf1e0.png)|
|![im_14.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/6b28127c-dcd9-927f-ce68-7c62ceb50da8.png)||![im_14.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/990d8ca3-c60e-9510-e432-327f15250a77.png)|
|![im_21.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/33f53093-a586-f2ac-8653-008de673f83d.png)||![im_21.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/3e9d1ef6-7678-fbf7-d705-2824b07edd8f.png)|
|![im_27.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/ad4cfa77-280e-15eb-224d-8a11eb2bf9b0.png)||![im_27.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/568ae8cd-e688-f923-c18f-8e619df310f9.png)|
|![rifle2.jpeg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/e83b09cd-0549-e0dc-ae40-e475b4f45bc0.jpeg)||![rifle2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/3e55f2bd-013f-a139-d086-c91d6e734c91.png)|
|![vangogh.jpeg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/0a3ee9c6-c049-877c-7c56-3bd1449d2a16.jpeg)||![vangogh.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/6e4aee67-4fac-4fed-947b-1678e251d6b1.png)|
|![whisk.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/3be4dae0-8507-a981-6d7f-a55a858cd423.png)||![whisk.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/e0c18a5e-c906-0b1d-d170-28fc30849ca7.png)|
-->

お疲れ様でした。

# 参考文献

[注目物体検出のU^2-Netやーる（Windows10、Python3.6）](https://qiita.com/SatoshiGachiFujimoto/items/680d7b07cb2bd347b184)