Skip to content

Commit

Permalink
Add SOLOv2 model
Browse files Browse the repository at this point in the history
  • Loading branch information
zymk9 committed Dec 25, 2020
1 parent d0c135b commit 09c3ddb
Show file tree
Hide file tree
Showing 4 changed files with 614 additions and 14 deletions.
35 changes: 26 additions & 9 deletions Anime_Segmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"metadata": {
"colab": {
"name": "Anime_Segmentation.ipynb",
"private_outputs": true,
"provenance": []
},
"kernelspec": {
Expand Down Expand Up @@ -47,10 +48,12 @@
"id": "7fpWsk8K7k3A"
},
"source": [
"# install detectron2: (Colab has CUDA 10.1 + torch 1.6)\n",
"# See https://detectron2.readthedocs.io/tutorials/install.html for instructions\n",
"assert torch.__version__.startswith(\"1.6\")\n",
"!pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.6/index.html\n",
"# install detectron2: (Colab has CUDA 10.1 + torch 1.7)\n",
"# tested on detectron2 v0.2-0.3\n",
"# See https://detectron2.readthedocs.io/tutorials/install.html for instructions if you \n",
"# want to switch to an older version\n",
"assert torch.__version__.startswith(\"1.7\")\n",
"!pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.7/index.html\n",
"clear_output()"
],
"execution_count": null,
Expand Down Expand Up @@ -78,9 +81,23 @@
"id": "zanbjXlI79PJ"
},
"source": [
"# download model weights and config \n",
"gdd.download_file_from_google_drive(file_id='1-AmeAiTrtaPcNLUnRAovpveMkSxxpkKQ', dest_path='./model.pth')\n",
"!wget https://github.com/zymk9/Yet-Another-Anime-Segmenter/raw/main/config.yaml"
"# download model weights and config\n",
"# CondInst \n",
"gdd.download_file_from_google_drive(file_id='1-AmeAiTrtaPcNLUnRAovpveMkSxxpkKQ', dest_path='./CondInst.pth')\n",
"!wget https://github.com/zymk9/Yet-Another-Anime-Segmenter/raw/main/configs/CondInst.yaml"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "LNzWghZ6ziNg"
},
"source": [
"# SOLOv2\r\n",
"gdd.download_file_from_google_drive(file_id='1-wFdQ4jwSTeJ7wGD3YKNJdcpSS5Ho8c9', dest_path='./SOLOv2.pth')\r\n",
"!wget https://github.com/zymk9/Yet-Another-Anime-Segmenter/raw/main/configs/SOLOv2.yaml"
],
"execution_count": null,
"outputs": []
Expand All @@ -92,10 +109,10 @@
},
"source": [
"# do inference\n",
"!python demo/demo.py --input ./input.jpg --config-file ./config.yaml --output /content/output.jpg --opts MODEL.WEIGHTS ./model.pth"
"!python demo/demo.py --input ./input.jpg --config-file ./SOLOv2.yaml --output /content/output.jpg --opts MODEL.WEIGHTS ./SOLOv2.pth"
],
"execution_count": null,
"outputs": []
}
]
}
}
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# Yet-Another-Anime-Segmenter

![sample1](./sample/64535234_p0_seg.jpg)
Instance segmentation for anime characters based on [CondInst](https://arxiv.org/abs/2003.05664), using the implementation from [AdelaiDet](https://github.com/aim-uofa/AdelaiDet) and [detectron2](https://github.com/facebookresearch/detectron2).
Instance segmentation for anime characters based on [CondInst](https://arxiv.org/abs/2003.05664) and [SOLOv2](https://arxiv.org/abs/2003.10152), using the implementation from [AdelaiDet](https://github.com/aim-uofa/AdelaiDet) and [detectron2](https://github.com/facebookresearch/detectron2).

Many thanks to [AniSeg](https://github.com/jerryli27/AniSeg) created by jerryli27, as part of the dataset originates from the segmentation data provided in this [repo](https://github.com/jerryli27/AniSeg#about-the-models). The rest of the dataset is retrieved from [Pixiv](https://www.pixiv.net/) and manually annotated.

A model based on SOLOv2 had been added, which generally outperforms previous CondInst model. Evaluation results may be added soon.

Newer version of the model is still under development, stay tuned if you are interested.

## Usage
### Installation
Both AdelaiDet and detectron2 are required. Please refer to the official guide from [AdelaiDet](https://github.com/aim-uofa/AdelaiDet#installation) and [detectron2](https://github.com/facebookresearch/detectron2/blob/master/INSTALL.md). A [Colab tutorial](https://github.com/zymk9/Yet-Another-Anime-Segmenter/blob/main/Anime_Segmentation.ipynb) is provided.
Both AdelaiDet and detectron2 are required. Please refer to the official guide from [AdelaiDet](https://github.com/aim-uofa/AdelaiDet#installation) and [detectron2](https://github.com/facebookresearch/detectron2/blob/master/INSTALL.md). A [Colab tutorial](https://colab.research.google.com/drive/1d49vI0lS2MKHx-j5VVnzPUhpRrNjueHI?usp=sharing) is provided.

### Inference
1. Download the [pretrained model](https://drive.google.com/file/d/1-AmeAiTrtaPcNLUnRAovpveMkSxxpkKQ/view?usp=sharing) and the [config file](https://github.com/zymk9/Yet-Another-Anime-Segmenter/blob/main/config.yaml).
1. Download the pretrained model and use the corresponding config file.
* CondInst: [model weights](https://drive.google.com/file/d/1-AmeAiTrtaPcNLUnRAovpveMkSxxpkKQ/view?usp=sharing), [config](./configs/CondInst.yaml).
* SOLOv2: [model weights](https://drive.google.com/file/d/1-wFdQ4jwSTeJ7wGD3YKNJdcpSS5Ho8c9/view?usp=sharing), [config](./configs/SOLOv2.yaml).

2. Run inference with
```bash
Expand All @@ -22,9 +26,9 @@ Both AdelaiDet and detectron2 are required. Please refer to the official guide f
--opts MODEL.WEIGHTS path/to/pretrained/model
```
## Training and Results
Training using transfer learning from a [pretrained model](https://github.com/aim-uofa/AdelaiDet#coco-instance-segmentation-baselines-with-condinst) on COCO Instance Segmentation. Parameters can be found in the [config file](https://github.com/zymk9/Yet-Another-Anime-Segmenter/blob/main/config.yaml).
Training using transfer learning from [pretrained models](https://github.com/aim-uofa/AdelaiDet/tree/master/configs/SOLOv2) on COCO Instance Segmentation. Parameters can be found in the [config file](./configs/SOLOv2.yaml).

Dataset is augmented by placing segmentations on pure backgrounds.
Dataset is augmented by placing segmentations on pure backgrounds. Models are trained with multi-scale augmentation.

![sample2](./sample/52206792_p0_seg.jpg)
![sample3](./sample/64113607_p0_seg.jpg)
File renamed without changes.
Loading

0 comments on commit 09c3ddb

Please sign in to comment.