Deep Metric Learning を使った MVTecAD データセットの異常検知に挑戦（Capsule編）

#はじめに
前回の記事に続いて、今回は、MVTec AD の Capsule に挑戦します。
https://qiita.com/tetz1/items/6f92928d482534f7d2c4

※コードは準備中です。

[](
※全体のコードはこちらに置いています。
（Google colab 上で実行するためのコードを含んでいます。）
https://github.com/nshikimi/MVTecAD/tree/master/Capsule
)

#データセット（MVTec AD）について（前回の繰り返し）
様々な製品（物体）について、正常な個体の画像と異常な個体の画像が含まれています。
また、異常な個体の画像には、多様な異常の種類が、きちんと分類されて含まれています。
さらに、素晴らしいのは、異常な部分を特定できるようなマスクがはじめから含まれていることです。（これは、本当に有り難いです。）
ただ、実際の現場で、このようなマスクを作るのは極めて手間がかかると思われるので、これに頼ると、その手法が実際の現場で使えない、ということが発生するかも知れません。
製品（物体）の種類は、bottle、cable、capsule、carpet、grid、hazelnut、leather、metal_nut、pill、screw、tile、toothbrush、transistor、wood、zipper の15種類です。
下記にて、入手できます。
https://www.mvtec.com/company/research/datasets/mvtec-ad/

#データのサンプル
正常データ

|![000.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/38da6000-c0a3-cf89-ab7c-638cdee4c10e.png)|![001.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/2c274cd4-7003-7f1a-04d2-3ab1ad4a43ab.png)|![002.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ace7392e-74de-b084-12bb-b1a163203201.png)|![003.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/4b34a169-cd21-a0d6-f33a-b495f6d12604.png)|![004.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/772c0024-478f-9282-644e-5b69d0b04d57.png)|
|---|---|---|---|---|


異常（crack）

|![000 (1).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/dfbf326c-f7b7-c4cc-7f78-98b1b3974d31.png)|![001 (1).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/6931b0b1-7da9-8884-8758-4d75e8dda60d.png)|![002 (1).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b8ddf119-7e48-e6a9-5d51-367fdbb94c0c.png)|![003 (1).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fc69ab9b-49d5-1ae4-57b5-592f0e982985.png)|![004 (1).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5e494daf-c110-f196-1d2a-84136014ae6a.png)|
|---|---|---|---|---|

異常（faulty_imprint）

|![000 (2).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/6dbcbda8-f33c-4b88-25e6-03a7a81d300c.png)|![001 (2).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8bc14ae1-56c7-527a-f91b-9c2cbc1224e5.png)|![002 (2).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/1744be69-3e7c-f54c-40de-0443a7b1a237.png)|![003 (2).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9a15aea6-25f8-e53f-3100-c85677906c1a.png)|![004 (2).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/0df3f1c1-ce3e-d224-222c-5364d2741e66.png)|
|---|---|---|---|---|

異常（poke）

|![000 (3).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/769116e3-2460-da9a-07ec-9aacb18dc78f.jpeg)|![001 (3).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b98dfeba-8f3e-4f42-0a27-21ca2b25673c.jpeg)|![002 (3).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d5c64e41-f03f-6a9d-9d62-a40df48532ec.jpeg)|![004 (3).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/cde8e8d9-777c-5170-307b-d60d420a91c7.jpeg)|![003 (3).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9216ff06-c5fb-0caf-0cc8-fed30d0462e9.jpeg)|
|---|---|---|---|---|

異常（scratch）

|![000 (4).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a66b5ce0-be71-b5bb-5e49-42220349983e.jpeg)|![001 (4).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ec9b8389-4380-8c50-8631-db8206c32c4e.jpeg)|![002 (4).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/03db4463-a214-f30b-64fa-1ec7a9704f8f.jpeg)|![003 (4).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e22c11b8-6ff1-504d-6bbe-4d1ddaf6c372.jpeg)|![004 (4).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d357050d-14bc-e77d-0cba-594e5e7fa0a1.jpeg)|
|---|---|---|---|---|

異常（squeeze）

|![000 (5).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5e5a7c5f-c46f-8d25-ca20-7c5dcf667fde.jpeg)|![001 (5).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9827f183-0ef8-1fa9-6a02-5d770238a13a.jpeg)|![002 (5).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/31a6b63f-e296-51ed-863c-2638fa0230d6.jpeg)|![003 (5).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/4662dc2c-7002-53e8-a9b5-04213f711b4b.jpeg)|![004 (5).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/122219e8-0fc3-5527-f6e7-e865dbbf3e2b.jpeg)|
|---|---|---|---|---|


#検証概要
今回の検証の概要は下記の通りです。

- 今回は、MVTecAD の Capsuleデータセットを使用
- MVTecAD のフォルダ構成
　　MVTecAD
　　　　|--- capsule
　　　　　　　　|--- train
　　　　　　　　|　　　|--- good
　　　　　　　　|--- Test
　　　　　　　　　　　|--- good
　　　　　　　　　　　|--- crack
　　　　　　　　　　　|--- faulty_print
　　　　　　　　　　　|--- poke
　　　　　　　　　　　|--- scratch
　　　　　　　　　　　|--- squeeze

- 下記のパターンを実施
    - 1000x1000の元画像を、512x512に resize して、正常と異常の二値分類問題として実施
    - 1000x1000の元画像を、512x512に resize して、各異常モードごとの多クラス分類として実施
    - 1000x1000の元画像を、400x900にクロップし、200x450に resize して、正常と異常との二値分類として実施
    - 1000x1000の元画像を、400x900にクロップし、200x450に resize して、各異常モードごとの多クラス分類として実施
    - 1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、対象物（カプセル）に、人工的に異常（複数色の直線）を加え、異常画像を増やして、各異常モードごとの多クラス分類として実施
    - 1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、対象物（カプセル）に、人工的に異常（白色のみの直線）を加え、異常画像を増やして、各異常モードごとの多クラス分類として実施
    - 1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、画像のシャープネスを加工し、各異常モードごとの多クラス分類として実施
    - 1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、画像の値を逆転させて（0〜1)の値を1-元の値(0〜1）に変換）し、各異常モードごとの多クラス分類として実施
    - 1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、対象物（カプセル）の画像を部分的に入れ替えることで、異常画像を増やして、正常と異常の二値分類として実施
    - 1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、対象物（カプセル）の画像を部分的に入れ替えることで、異常画像を増やして、各異常モードごとの多クラス分類として実施
- 学習には、正常だけで構成される trainフォルダのデータだけでなく、testフォルダの異常データも使用
- 学習、予測に使用した TrainデータとTestデータは、 trainフォルダ、testフォルダの正常データと異常データを、各サブフォルダごとに8：2に分割して、作成、使用
- NNには、ResNet18を使用
- 学習には、Metric Learning/AdaCos を使用
- Epoch数は100〜700/900 （学習が遅いもの、学習を進めて見たら変化がありそうなもの（無根拠）は900です。）
- lr はすべて 0.1 で実施

#検証結果
##モデルの学習と特徴空間へのプロット
エポック数100〜700で学習したモデルから、Metric Learningの特徴（512次元）を抽出し、UMAPで2次元に可視化したものが下記のとおり。

###1000x1000の元画像を、512x512に resize して、正常と異常の二値分類問題として実施

####データ
使用したデータは、オリジナルデータ（1000*1000)を512*512にresizeしたもので、見た目は上記のオリジナルデータと同じ（正方形）

####結果
|エポック数|trainデータ|testデータ|train+testデータ|
|---|---|---|---|
|100|![1000_1000_UMAP_multi_100_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a6ba2fc9-27c1-c5f6-5d7d-225dbcb741ae.jpeg)|![1000_1000_UMAP_multi_100_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fccb8dd4-8217-7a74-6851-75661f1cd7c4.jpeg)|![1000_1000_UMAP_multi_100_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8870719b-28bd-5fa0-9bf5-91563db4b3aa.jpeg)|
|200|![1000_1000_UMAP_multi_200_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ac429653-2de4-2ca4-5088-13f4dff4c793.jpeg)|![1000_1000_UMAP_multi_200_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/48f36e02-8455-c8df-75c6-cc2f5d693a6b.jpeg)|![1000_1000_UMAP_multi_200_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/97e2cc87-ace3-380a-0d4d-3ac81ebfaa69.jpeg)|
|300|![1000_1000_UMAP_multi_300_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/53b271a6-be29-cfff-acb0-e98c81c5206f.jpeg)|![1000_1000_UMAP_multi_300_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/2e77cfeb-1c3c-776a-7c1e-ce19515a8fe0.jpeg)|![1000_1000_UMAP_multi_300_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/416e2af4-869a-3769-7423-550f32ccc25b.jpeg)|
|400|![1000_1000_UMAP_multi_400_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/1fd6dc32-f2b2-b894-5728-5ae3d3628ad4.jpeg)|![1000_1000_UMAP_multi_400_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b5d7d1bd-6ad6-a064-afe0-9cb6d9fd8602.jpeg)|![1000_1000_UMAP_multi_400_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/bc3b65b1-eaf9-20b6-cdf2-76091a73969f.jpeg)|
|500|![1000_1000_UMAP_multi_500_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/27ce7972-7fb2-f211-ad88-7bc722f543c1.jpeg)|![1000_1000_UMAP_multi_500_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ff0a4cf2-e526-f8a2-be69-31a4fec4f580.jpeg)|![1000_1000_UMAP_multi_500_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/243357de-8aac-9a0f-2b48-a6a75b6f0317.jpeg)|
|600|![1000_1000_UMAP_multi_600_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/163a7e0b-78a6-9b84-f919-01e86cdb58be.jpeg)|![1000_1000_UMAP_multi_600_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b5936001-79b4-3994-3611-0d12baa02f75.jpeg)|![1000_1000_UMAP_multi_600_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e7c5ec98-c3a4-417a-bac5-2514fb2051fe.jpeg)|
|700|![1000_1000_UMAP_multi_700_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/12e093b7-6499-b04d-a5c1-cc72f6b09a4e.jpeg)|![1000_1000_UMAP_multi_700_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fe058c33-e952-393f-0c30-f78cc03e31af.jpeg)|![1000_1000_UMAP_multi_700_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/1f13ef37-483f-1e1f-a301-4e2a71811b44.jpeg)|
|800|![1000_1000_binary_800_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e1a650c6-ab85-8dc9-d43e-f5c1ebdf7670.jpeg)|![1000_1000_binary_800_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fdf28b36-66dd-206a-ce22-277697c182d1.jpeg)|![1000_1000_binary_800_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b2ee7e30-377b-a270-d0c3-38553ca0f3b8.jpeg)|
|900|![1000_1000_binary_900_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8ad2d590-e9bd-9b50-f9b8-2fafbc03a123.jpeg)|![1000_1000_binary_900_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ef99ee03-60a8-ea51-c8e5-3e8b8ed854be.jpeg)|![1000_1000_binary_900_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/be8ecaff-584e-5d43-0d86-f49f65ee32c6.jpeg)|

※ 学習は二値分類問題として実施しましたが、各異常モードごとの差異がわかるように、推論とプロットは多クラスで行っています。

####考察
学習には結構時間がかかっています。
エポック500あたりで落ち着いて来てますが、エポック500ではかなりきれいに分離・予測できています。
何も手を加えていないのに、ここまで分離・予測できるのは驚きです。


###1000x1000の元画像を、512x512に resize して、各異常モードごとの多クラス分類として実施

####データ
使用したデータは、オリジナルデータ（1000*1000)を512*512にresizeしたもので、見た目は上記のオリジナルデータと同じ（正方形）


####結果
|エポック数|trainデータ|testデータ|train+testデータ|
|---|---|---|---|
|100|![1000_1000_UMAP_binary_100_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5c77fb30-40ba-8433-e820-aece4f7a9c9e.jpeg)|![1000_1000_UMAP_binary_100_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/de64a6bb-6f45-b2f5-384b-87c1eabf1a62.jpeg)|![1000_1000_UMAP_binary_100_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/3c5f1ab4-7962-1fc8-88c7-6258f1fe5774.jpeg)|
|200|![1000_1000_UMAP_binary_200_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9dc08b60-ed88-6214-ab93-52ad69baa98d.jpeg)|![1000_1000_UMAP_binary_200_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a3503c88-f307-0d84-669a-a37b04b639d4.jpeg)|![1000_1000_UMAP_binary_200_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a57770ee-d2f7-008a-7560-4c1877564e31.jpeg)|
|300|![1000_1000_UMAP_binary_300_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/51ae9359-e769-2a7c-cad9-f63342a81f94.jpeg)|![1000_1000_UMAP_binary_300_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5a1f290a-7e50-c10d-b5dc-1c1fc63043ff.jpeg)|![1000_1000_UMAP_binary_300_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/801c3a73-329e-a5c2-59a5-56afd549e8b1.jpeg)|
|400|![1000_1000_UMAP_binary_400_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b47f4b12-77fd-b077-02a0-1e73d8fe2c2d.jpeg)|![1000_1000_UMAP_binary_400_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/40273741-8fe4-26b7-4b5f-30160ffc97c3.jpeg)|![1000_1000_UMAP_binary_400_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/abf88802-8bf4-ab3a-94c8-a780d4c77afc.jpeg)|
|500|![1000_1000_UMAP_binary_500_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/39bfdc66-5c33-7fa7-5e16-6951cecb8b05.jpeg)|![1000_1000_UMAP_binary_500_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b9102650-5c20-9de4-c5c6-5594f30652aa.jpeg)|![1000_1000_UMAP_binary_500_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/c3f744f2-f34f-7457-5590-2a9d017cd9bf.jpeg)|
|600|![1000_1000_UMAP_binary_600_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/7d405157-92fd-2042-4416-ea9f3cdecc17.jpeg)|![1000_1000_UMAP_binary_600_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/1145dde5-5ce1-eb74-d66b-eccd4efdfd26.jpeg)|![1000_1000_UMAP_binary_600_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b6d6bb88-9580-1e0e-78b1-acfa29bd7efb.jpeg)|
|700|![1000_1000_UMAP_binary_700_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fc15f043-d0be-1a05-f3fa-f11879b65108.jpeg)|![1000_1000_UMAP_binary_700_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8f72d502-af71-a1cf-3938-3f73c21d39e8.jpeg)|![1000_1000_UMAP_binary_700_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/c85942a5-67bf-eb8e-7feb-73931859da20.jpeg)|
|800|![1000_1000_multi_800_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/c16e14c6-bfe8-f381-1112-8004b5f90901.jpeg)|![1000_1000_multi_800_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/846f6d06-7114-f8a1-91d9-3ccb5a496c2f.jpeg)|![1000_1000_multi_800_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/4b4e596e-28fc-ee39-e51a-3bf27163160e.jpeg)|
|900|![1000_1000_multi_900_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5e1434f5-5851-c9d4-1522-4acddd1a9a5e.jpeg)|![1000_1000_multi_900_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/578b50cf-574f-21ba-14c2-8141c6b948c7.jpeg)|![1000_1000_multi_900_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ec950002-ab18-892d-8f9e-52fa6951cb51.jpeg)|


####考察
二値分類に比べ、早く学習が進んでいます。（エポック200あたりで落ち着いて来ています。）
エポック500が最もよさそうです。
多クラス分類にした方が、それぞれの異常モードの特徴を分けて捉えることができるかと思ったのですが、課題が複雑になってしまったのか、サンプル数が足りなかったのか、二値分類より精度が低下してしまいました。


###1000x1000の元画像を、400x900にクロップし、200x450に resize して、正常と異常との二値分類として実施

####データ

|正常|crack|imprint|
|---|---|---|
|![400_900_ori_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fb24ea8c-d619-2564-2365-6c736beefc09.png)|![400_900_ori_2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8eb35a58-a722-1002-3f1c-a1f2a037aa67.png)|![400_900_ori_3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e9dc807f-119d-6d8c-7a4b-cf5718b6a38d.png)|

|poke|scratch|squeeze|
|---|---|---|
|![400_900_ori_4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8a4d86df-5b7f-4673-6568-88d20721cf42.png)|![400_900_ori_5.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b1be32b7-a628-f0da-5312-e97ef9a4b3fe.png)|![400_900_ori_6.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/af91dfd6-2cbe-84a5-8f9f-a649cfdc63e4.png)|


####結果
|エポック数|trainデータ|testデータ|train+testデータ|
|---|---|---|---|
|100|![t_400_900_binary_UMAP_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d8d972dd-eca6-ad5b-1991-adb940a4db87.jpeg)|![v_400_900_binary_UMAP_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/7a51ed93-cec9-60ff-b16d-8c96035ef996.jpeg)|![a_400_900_binary_UMAP_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/f4c79585-322b-d90b-8e26-bcb5888e16ed.jpeg)|
|200|![t_400_900_binary_UMAP_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/895f197f-5edb-4ff3-8938-80a06b32f519.jpeg)|![v_400_900_binary_UMAP_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/6212b0c1-84da-5e14-2221-e29edfe7c0fe.jpeg)|![a_400_900_binary_UMAP_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/6208e733-cee7-347e-0d0a-8a63124a42a3.jpeg)|
|300|![t_400_900_binary_UMAP_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/f9e588a8-b4bc-bc22-4899-67df37e9ebec.jpeg)|![v_400_900_binary_UMAP_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/aca0b9a6-d377-2955-f902-84c0cd9a760d.jpeg)|![a_400_900_binary_UMAP_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/060519ab-bf6c-8f97-6c83-7ea850c1835d.jpeg)|
|400|![t_400_900_binary_UMAP_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/305c3259-1e1a-ccbb-18b7-1b83fd55ec37.jpeg)|![v_400_900_binary_UMAP_400.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/7de2b592-ac28-d0dd-c747-99f372ba424f.png)|![a_400_900_binary_UMAP_400.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5ebe27ea-6a9f-74f4-e4e2-2f67a2584c55.png)|
|500|![t_400_900_binary_UMAP_500.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/638147f1-ad43-1cfb-9b31-7a39936eac4f.png)|![v_400_900_binary_UMAP_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/4d75d2f8-79cc-717c-24fd-b1643341ba37.jpeg)|![a_400_900_binary_UMAP_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8b6cfb12-5802-d108-ee7d-c8c5ff059052.jpeg)|
|600|![t_400_900_binary_UMAP_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d1797206-1bba-5a1f-ba6d-f8581b64a63d.jpeg)|![v_400_900_binary_UMAP_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/3538ce40-14b1-b13f-c4f7-f00ad82fdaa7.jpeg)|![a_400_900_binary_UMAP_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d32e9b2f-dc07-5555-6758-9745e6bc252e.jpeg)|
|700|![t_400_900_binary_UMAP_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/564a50cd-0488-9381-0748-29c9eedd2d62.jpeg)|![v_400_900_binary_UMAP_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/58765c05-4ca2-1732-13fb-dabdca88fda7.jpeg)|![a_400_900_binary_UMAP_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/29127ee6-7a5e-fdd5-7294-0f77cfdfc4d6.jpeg)|

※ 学習は二値分類問題として実施しましたが、各異常モードごとの差異がわかるように、推論とプロットは多クラスで行っています。

####考察
かなり早く学習が進んでいます。（エポック100ですでに落ち着いて来ています。）
また、サイズを落としたことで、各エポックの学習にかかる時間も大幅に短縮されています。
エポック500では、異常データが一点だけ正常のエリアにプロットされている以外は、非常にきれいに分離・予測できています。
このモデルが、今回のすべてのモデル中で最も精度がいいという結果になりました。


###1000x1000の元画像を、400x900にクロップし、200x450に resize して、各異常モードごとの多クラス分類として実施

####データ

|正常|crack|imprint|
|---|---|---|
|![400_900_ori_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fb24ea8c-d619-2564-2365-6c736beefc09.png)|![400_900_ori_2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8eb35a58-a722-1002-3f1c-a1f2a037aa67.png)|![400_900_ori_3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e9dc807f-119d-6d8c-7a4b-cf5718b6a38d.png)|

|poke|scratch|squeeze|
|---|---|---|
|![400_900_ori_4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8a4d86df-5b7f-4673-6568-88d20721cf42.png)|![400_900_ori_5.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b1be32b7-a628-f0da-5312-e97ef9a4b3fe.png)|![400_900_ori_6.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/af91dfd6-2cbe-84a5-8f9f-a649cfdc63e4.png)|

※ ラベル以外は、上記の二値分類と同じデータです。

####結果
|エポック数|trainデータ|testデータ|train+testデータ|
|---|---|---|---|
|100|![train_400_900_multi_UMAP_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/06824f3a-9664-c26d-4b74-9a2002a3177d.jpeg)|![test_400_900_multi_UMAP_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/1bc4bf2d-7b2d-f6de-5845-a75f86f82b67.jpeg)|![all_400_900_multi_UMAP_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8e0ccb71-048e-8aa4-fcd8-a79dd2aeeb2f.jpeg)|
|200|![train_400_900_multi_UMAP_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/22527f56-e150-4d5c-dfba-2befa90db577.jpeg)|![test_400_900_multi_UMAP_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/02a97c85-d608-c3d1-dc04-f6adb15b7f41.jpeg)|![all_400_900_multi_UMAP_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/757dd722-e330-8306-5d6d-21a68ee13eb3.jpeg)|
|300|![train_400_900_multi_UMAP_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e6261fe2-77dc-12ee-04fa-52f52731dfd8.jpeg)|![test_400_900_multi_UMAP_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/f2d3753b-5f82-dad6-3a79-62a68dc67925.jpeg)|![all_400_900_multi_UMAP_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/650569b8-3d80-6fe3-248c-e273bcbf5a6f.jpeg)|
|400|![train_400_900_multi_UMAP_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b9dde9f1-a9c8-b4ff-554d-08d30ae7a369.jpeg)|![test_400_900_multi_UMAP_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5e259b2d-6b77-74b1-5d35-7e2443eae60b.jpeg)|![all_400_900_multi_UMAP_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/eac468f0-e66d-2e9c-d83b-41984bb6d119.jpeg)|
|500|![train_400_900_multi_UMAP_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/54ac29af-470c-f72f-1866-7077daf20b55.jpeg)|![test_400_900_multi_UMAP_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/69a001a5-a4c6-2666-4869-70ef037bb87a.jpeg)|![all_400_900_multi_UMAP_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/bde4c5c8-24fe-c970-07ad-da0bb6282d89.jpeg)|
|600|![train_400_900_multi_UMAP_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8ea5c995-022f-73e3-a281-78ee88948cb7.jpeg)|![test_400_900_multi_UMAP_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/06ba3b60-0982-1410-ea6c-815c7ac0e6f8.jpeg)|![all_400_900_multi_UMAP_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/3078b120-f3e8-5f49-3493-9c419b5a3520.jpeg)|
|700|![train_400_900_multi_UMAP_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ee315651-f7b7-22c9-fd40-d1a34cc0715f.jpeg)|![test_400_900_multi_UMAP_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/742fd644-c902-b32e-6f79-488991dd2b77.jpeg)|![all_400_900_multi_UMAP_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d42cab93-ea52-1e9b-2812-b25a5e8ffb35.jpeg)|

####考察
こちらも学習は早く進んでいます。
こちらも、エポック500が最も優れているようです。
ただし、二値分類と比較して、わずかに劣化しているようです。


###1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、対象物（カプセル）に、人工的に異常（複数色の直線）を加え、異常画像を増やして、各異常モードごとの多クラス分類として実施

####データ

|生成異常①|生成異常②|生成異常③|生成異常④|
|---|---|---|---|
|![400_900_defect_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/0d262687-910b-b305-ed39-6ff3fb123f37.png)|![400_900_defect_1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a26b3f3c-6728-d1d3-fd21-07946905f98d.png)|![400_900_defect_2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/22109ad6-a322-2f57-70fd-bb43a4e414d1.png)|![400_900_defect_3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/58422841-25b7-92d2-7357-551c6f1c3739.png)|


####結果

|エポック数|trainデータ|testデータ|train+testデータ|
|---|---|---|---|
|100|![t_400_900_w_defect_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/328c394c-5a9c-c41b-4ad3-ef3008b052be.jpeg)|![v_400_900_w_defect_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d38e1db3-e42f-edc0-cb5f-b275d6786f9b.jpeg)|![a_400_900_w_defect_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9a1f60b4-7ee4-f5e2-9b99-259ebe31a33b.jpeg)|
|200|![t_400_900_w_defect_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8a176e25-19b1-d8b7-1864-75558102fe88.jpeg)|![v_400_900_w_defect_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ede1d9d0-e06f-aae7-0f44-45aa67b0f0d8.jpeg)|![a_400_900_w_defect_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ea97a180-dd70-7358-17b6-044553264d2a.jpeg)|
|300|![t_400_900_w_defect_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/dfc689ce-c60c-7c77-d433-c4a146b2ee38.jpeg)|![v_400_900_w_defect_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/6e7e11e2-9f3c-7114-b8bb-43e3773f004e.jpeg)|![a_400_900_w_defect_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/57608a97-31af-3918-10bb-a50378ef3972.jpeg)|
|400|![t_400_900_w_defect_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/c8aa95bb-9799-a38c-537d-7f58b28da6e3.jpeg)|![v_400_900_w_defect_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a7fa51ac-145d-b3e5-618e-ab885dd46f51.jpeg)|![a_400_900_w_defect_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e73d7ef8-adcb-cd7b-88a9-6f18ce285700.jpeg)|
|500|![t_400_900_w_defect_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/4c8efe0c-0c88-0a3f-3f1f-00a8e8ef1c3b.jpeg)|![v_400_900_w_defect_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/821b7a09-aca7-0c08-7428-8f1f76c17866.jpeg)|![a_400_900_w_defect_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d15b3af7-8fa3-c942-257a-a1126d9a272f.jpeg)|
|600|![t_400_900_w_defect_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/748ae176-df8e-fe67-f1a8-2c7a12a8afbd.jpeg)|![v_400_900_w_defect_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/7fb4cf97-eb36-cfbf-4030-5b682be3cc15.jpeg)|![a_400_900_w_defect_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/1d18545a-f47f-a34e-7d4e-3d573ba4f97d.jpeg)|
|700|![t_400_900_w_defect_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d9bd02e6-7c43-4f8d-cb5f-97d29c94fcb6.jpeg)|![v_400_900_w_defect_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b765d445-9607-41b9-6bc5-5c3b4bf99f10.jpeg)|![a_400_900_w_defect_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/1189e50a-0c26-9ea1-943a-b616aa3a989d.jpeg)|

####考察
生成した異常データは、正常データに加工をしたもののみ（異常データを加工したものはない）です。
異常データを生成してデータ数を増やしているので、エポックあたりの学習時間が増加し、学習の進む速度も遅くなっています。（エポック400あたりで落ち着いて来ています。）
エポック400が最も精度が良さそうです。
ただし、他の手法に比べて、特に優れているとは言えないようです。


###1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、対象物（カプセル）に、人工的に異常（白色のみの直線）を加え、異常画像を増やして、各異常モードごとの多クラス分類として実施

####データ

|生成異常①|生成異常②|生成異常③|生成異常④|
|---|---|---|---|
|![400_900_defect_white_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/eb34bde9-3c8e-200d-088c-55b98baced4c.png)|![400_900_defect_white_1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/bd891f44-37d4-e24a-f0f2-6d0cb5899820.png)|![400_900_defect_white_2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a3dacc48-60e2-082f-20b0-dbb9bbfcd993.png)|![400_900_defect_white_3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/730d6a83-2fb8-17f7-497a-c08485377d70.png)|


####結果

|エポック数|trainデータ|testデータ|train+testデータ|
|---|---|---|---|
|100|![400_900_UMAP_defect_white_multi_100_t .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/2ceb9734-e1a4-89b2-8162-a736fd5101ae.jpeg)|![400_900_UMAP_defect_white_multi_100_v .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/f6f31212-b8fd-8e99-7e3b-ea89d62be9dc.jpeg)|![400_900_UMAP_defect_white_multi_100_a .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/4531333e-91e2-5ea8-c537-2defc086c14a.jpeg)|
|200|![400_900_UMAP_defect_white_multi_200_t .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/04234f98-e4a8-a1be-2306-bc8f37fde2a1.jpeg)|![400_900_UMAP_defect_white_multi_200_v .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a3fd51c5-d760-4591-ceb8-0bc084d42d68.jpeg)|![400_900_UMAP_defect_white_multi_200_a .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/90e6a936-7d6f-0782-a3ef-187d2d9d870f.jpeg)|
|300|![400_900_UMAP_defect_white_multi_300_ t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/6d33def1-adb2-89f5-4440-ed5bd47961c3.jpeg)|![400_900_UMAP_defect_white_multi_300_v .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e3cb276b-22b2-4f13-1749-473e85f1728c.jpeg)|![400_900_UMAP_defect_white_multi_300_a .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9daca129-ccd6-09ef-9709-e0eff1cfad0b.jpeg)|
|400|![400_900_UMAP_defect_white_multi_400_t .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/bebeb0a4-a5c1-23d2-b164-75d3c9b04a58.jpeg)|![400_900_UMAP_defect_white_multi_400_v .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ca460f4b-c416-f538-ab78-cd6e722f3010.jpeg)|![400_900_UMAP_defect_white_multi_400_a .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/7b848c70-6b5f-40d7-f480-48bb4951397c.jpeg)|
|500|![400_900_UMAP_defect_white_multi_500_t .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/cbab0ecf-7ee6-c5a5-a0d0-8b8251a6f820.jpeg)|![400_900_UMAP_defect_white_multi_500_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/78327935-6a82-60b7-765d-82cb40f283d0.jpeg)|![400_900_UMAP_defect_white_multi_500_a .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8f026134-fa2d-bccc-26cc-fdb44ae6811f.jpeg)|
|600|![400_900_UMAP_defect_white_multi_600_t .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/29c96cc3-b663-f3af-171e-095c48fadcf6.jpeg)|![400_900_UMAP_defect_white_multi_600_v .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/1a16e2f5-14f3-faba-2de9-85e3097f4264.jpeg)|![400_900_UMAP_defect_white_multi_600_a .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/c97dd5fe-d4d3-e728-f02c-bb5f0fb01045.jpeg)|
|700|![400_900_UMAP_defect_white_multi_700_t .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b2038004-ea71-9561-06fb-dd8afd4d1bf9.jpeg)|![400_900_UMAP_defect_white_multi_700_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/860352eb-f4aa-6950-065b-8aad8f48cf4f.jpeg)|![400_900_UMAP_defect_white_multi_700_a .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/71c4af2e-f9f8-e679-8852-42c6bfb40769.jpeg)|
|800|![400_900_UMAP_defect_white_multi_800_t .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/963524f3-0673-eff1-687a-0ac9bd5b845c.jpeg)|![400_900_UMAP_defect_white_multi_800_v .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/4642041a-b0b1-dfcd-3c36-8679b503248a.jpeg)|![400_900_UMAP_defect_white_multi_800_a .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/cd992289-afc1-8427-e08d-0e0919d5c40d.jpeg)|
|900|![400_900_UMAP_defect_white_multi_900_t .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/bb940cd4-c94c-8d80-7140-94ee493f3043.jpeg)|![400_900_defect_white_multi_900_v_change.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e399b15a-0031-379d-9b10-e25cfb0f0575.jpeg)|![400_900_UMAP_defect_white_multi_900_a .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fe2c20c6-c334-7112-0e9a-f525f813706a.jpeg)|


####考察
上と同じく、生成した異常データは、正常データに加工をしたもののみ（異常データを加工したものはない）です。
今回は、追加する異常は、白い線のみとしました。（実際の異常でも、異常個所はほとんどが白い（中身の白い粉末の色）ため）。また、少し、線を細くしました。
上と同じく、異常データを生成してデータ数を増やしているので、エポックあたりの学習時間が増加し、学習の進む速度も遅くなっています。（エポック300あたりで落ち着いて来ています。）
エポック700あたりが最も良さそうです。
上の複数の色で異常を生成したものよりはよさそうですが、他の手法に比べて、特に優れているとは言えないようです。


###1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、画像のシャープネスを加工し、各異常モードごとの多クラス分類として実施

|正常|crack|imprint|
|---|---|---|
|![400_900_iaa_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8b38240f-f0f1-01b9-d048-9123af0def14.png)|![400_900_iaa_2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/defdad8f-4f0d-92ca-0ea4-ca9f0c35234b.png)|![400_900_iaa_3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/0f3ba0c0-7ae3-565b-31ac-d82af01b681b.png)|

|poke|scratch|squeeze|
|---|---|---|
|![400_900_iaa_4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9378d073-dc06-6e83-21b6-923ad54d68ad.png)|![400_900_iaa_5.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/88f1370d-893d-71a9-799d-7c5ce2242b4d.png)|![400_900_iaa_6.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/459559b0-32ab-8c95-77c1-92d1a9d1bd3d.png)||

####結果

|エポック数|trainデータ|testデータ|train+testデータ|
|---|---|---|---|
|100|![t_400_900_UMAP_iaa_multi_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/2a848545-5ae3-20f0-a288-5a2fd7974e45.jpeg)|![v_400_900_UMAP_iaa_multi_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/2b487eac-6043-37c4-78f3-24b4e215957b.jpeg)|![a_400_900_UMAP_iaa_multi_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/aa2dc5cd-1f83-4dc3-f402-f1897603cde6.jpeg)|
|200|![t_400_900_UMAP_iaa_multi_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a4d8506c-a700-8e49-dd8e-c4e5f36f4352.jpeg)|![v_400_900_UMAP_iaa_multi_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/83d6f94a-a0c7-864e-d542-e2bdb86b7b0d.jpeg)|![a_400_900_UMAP_iaa_multi_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e23ddb21-4a4c-988e-2f09-4585032dcab7.jpeg)|
|300|![t_400_900_UMAP_iaa_multi_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/f81a7149-b6c3-f993-7e08-379601b8af1e.jpeg)|![v_400_900_UMAP_iaa_multi_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a439db9d-549e-a60d-f16f-adfd73ef4449.jpeg)|![a_400_900_UMAP_iaa_multi_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ebf31916-1a79-de5a-4cdd-b97fdc4083fa.jpeg)|
|400|![t_400_900_UMAP_iaa_multi_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a2b9f3fd-a2d1-f367-4aa1-83475171e13b.jpeg)|![v_400_900_UMAP_iaa_multi_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a1600769-cf97-f7ee-0128-accfa96cd775.jpeg)|![a_400_900_UMAP_iaa_multi_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/822a659a-47e2-7bda-51c0-d6bf84b554c2.jpeg)|
|500|![400_900_UMAP_iaa_multi_500_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/3c721850-52bf-6ade-9986-feec0a270f2b.jpeg)|![400_900_UMAP_iaa_multi_500_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b2296f6b-c9b3-7534-d89c-87be4c825c8e.jpeg)|![400_900_UMAP_iaa_multi_500_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/01fd8829-229d-0e31-fe4b-6c38875303df.jpeg)|
|600|![400_900_UMAP_iaa_multi_600_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5e5c9b53-2514-39b3-3093-918903c90f25.jpeg)|![400_900_UMAP_iaa_multi_600_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/0d5de7a6-b7ef-4be0-c1d7-74b3dbff959d.jpeg)|![400_900_UMAP_iaa_multi_600_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/4d875960-6e3d-26c3-53b9-2401cf1b4a15.jpeg)|
|700|![400_900_UMAP_iaa_multi_700_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a853de9d-3595-6921-3c89-f53e304dd79c.jpeg)|![400_900_UMAP_iaa_multi_700_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/45e81493-3029-aef8-8902-0ea16a128ad1.jpeg)|![400_900_UMAP_iaa_multi_700_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/26d44938-e24c-b5b8-48d4-899d786c9768.jpeg)|

[](![400_900_iaa_800_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ea9280b0-cf48-ccfa-c75e-c7b23b1a29ba.jpeg)
![400_900_iaa_800_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5cc728a0-aa68-6f93-b25e-f2143a42b87a.jpeg)
![400_900_iaa_800_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/6879a5d6-b268-aa5d-4aeb-f1bcb9f5da94.jpeg)
)

####考察
画像を加工して、異常が（人間の目で見て）目立つようにしてみたのですが、ほとんど効果はありませんでした。
（この手の加工（処理）は、基本的にはニューーラルネットワークの中で行う処理と重複しているらしくです。）


###1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、画像の値を逆転させて（０〜１の値を1-元の値(0〜1）に変換）し、各異常モードごとの多クラス分類として実施

|正常|crack|imprint|
|---|---|---|
|![400_900_reverse_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a50b6d10-2721-634a-397c-3ee0243c40fb.png)|![400_900_reverse_2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/85499c15-d5be-86e9-9a83-b0f8c3b2a7a4.png)|![400_900_reverse_3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a4ee4606-a730-524a-6b01-4f308d779b1e.png)|

|poke|scratch|squeeze|
|---|---|---|
|![400_900_reverse_4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/c535dc6f-6e4b-db25-9a51-da68b7fd21b9.png)|![400_900_reverse_5.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/1484be3e-e83a-415c-60c6-9871fa3e3d5b.png)|![400_900_reverse_6.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/74819192-30a7-dc59-a7a2-bb42a81314ef.png)|


####結果
|エポック数|trainデータ|testデータ|train+testデータ|
|---|---|---|---|
|100|![400_900_UMAP_reverse_multi_100_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/45d8088c-4555-f680-20f5-5ba9c2a2901a.jpeg)|![400_900_UMAP_reverse_multi_100_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8cbcfc01-a351-7b52-e6e1-e56e9823fde6.jpeg)|![400_900_UMAP_reverse_multi_100_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/6c06be77-34dc-f5f3-69e6-94af5d4c431e.jpeg)|
|200|![400_900_UMAP_reverse_multi_200_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/7ffe8adb-519a-4211-112d-e2493b3d6c1d.jpeg)|![400_900_UMAP_reverse_multi_200_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e26ef713-95c7-37c6-989b-6885b2719dc7.jpeg)|![400_900_UMAP_reverse_multi_200_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b6e18004-537f-623f-0403-35939e266af3.jpeg)|
|300|![400_900_UMAP_reverse_multi_300_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/321b6d0f-6afe-01e1-6f68-dfd31c5231c9.jpeg)|![400_900_UMAP_reverse_multi_300_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9b7ef4f1-b69e-900e-de34-45609b13edb3.jpeg)|![400_900_UMAP_reverse_multi_300_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/79d69b89-0dd8-78cc-38b4-6e6bc1dfa905.jpeg)|
|4400|![400_900_UMAP_reverse_multi_400_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e1728130-f4fd-67e0-fb11-9450389a230c.jpeg)|![400_900_UMAP_reverse_multi_400_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/4cfa8502-4eea-025c-8550-f7b0e3392f83.jpeg)|![400_900_UMAP_reverse_multi_400_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/13ac3bfc-140c-01ac-0e96-598e97be01b8.jpeg)|
|500|![400_900_UMAP_reverse_multi_500_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/62954dd4-7cc4-9cc5-78af-235198d29254.jpeg)|![400_900_UMAP_reverse_multi_500_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/73c17b79-28e0-e8b9-103d-336dd5c5fc7a.jpeg)|![400_900_UMAP_reverse_multi_500_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d735516d-c94d-bff6-1717-f90a1f6c0c92.jpeg)|
|600|![400_900_UMAP_reverse_multi_600_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/64cad3a1-cd3d-d5c0-1824-52bcaff41572.jpeg)|![400_900_UMAP_reverse_multi_600_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/49bfd097-e3b3-9fb2-630a-89a09648db0f.jpeg)|![400_900_UMAP_reverse_multi_600_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/836541c4-59e7-b5c9-ad3d-3350ca0a0bda.jpeg)|
|700|![400_900_UMAP_reverse_multi_700_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/6146ba6e-533f-fe52-988f-9f3868002fdf.jpeg)|![400_900_UMAP_reverse_multi_700_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fccedb52-7956-11e8-6027-455a84426971.jpeg)|![400_900_UMAP_reverse_multi_700_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/c2bf4d09-1beb-9a6d-799f-8388ca224bd3.jpeg)|
|800|![400_900_UMAP_reverse_multi_800_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/37d33a0a-f604-32d1-ed98-9b84f3c43bda.jpeg)|![400_900_UMAP_reverse_multi_800_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/f861699f-1f64-51b2-2acf-9b797633796f.jpeg)|![400_900_UMAP_reverse_multi_800_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e5046986-f1bb-f7a1-1ea9-4ee93584ec68.jpeg)|
|900|![400_900_UMAP_reverse_multi_900_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/3b4a04d3-4492-839a-ea13-220f6505ad3e.jpeg)|![400_900_UMAP_reverse_multi_900_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/395dcbcf-37a6-842e-1f59-5f024e9cc394.jpeg)|![400_900_UMAP_reverse_multi_900_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/bc68f674-0568-72a2-a680-3e74b2941580.jpeg)|

####考察
学習・推論には不要な背景が白く、カプセルの一部が黒いので、学習に必要のない背景を0にして、学習に必要なカプセル本体を1に近づけることで何かが変わるかもと思ったのですが、何の効果もないどころか、精度が低下してしまいました。


###1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、対象物（カプセル）の画像を部分的に入れ替えることで、異常画像を増やして、正常と異常の二値分類として実施

####データ

|元画像|加工後|
|---|---|
|![図4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/09a4d071-e6dc-8ee8-ed71-b4f6fdc398a0.png)|![図2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/dd680be2-02c8-4d8a-f620-247b4bf7d036.png)|
|![図3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9ae22c59-f7da-647b-b94d-e5e2f11d91cf.png)|![図5.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/0787206b-421b-fb99-2d45-d2febb0c591c.png)|

緑の枠線で囲った部分を左右入れ替えて、異常データを水増ししています。

|crack|imprint|poke|
|---|---|---|
|![400_900_switch1_1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/97b28158-5d03-a2d1-b48b-d6e5ef8a8a06.png)|![400_900_switch1_2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fecb507e-7077-35ae-4e0a-1f492164f8d4.png)|![400_900_switch1_3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ed9748e2-6c8f-219f-6775-50143bec1ba2.png)|

|scratch|squeeze|
|---|---|
![400_900_switch1_4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/631bee0c-bd67-26d8-f350-9b9314ee961c.png)|![400_900_switch1_5.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/290ad1f4-9647-736a-9cc5-3557e79da0ba.png)|


※コードの一部に間違いがあったので、下記のプロット図は間もなく修正します。申し訳ありません。

####結果
|エポック数|trainデータ|testデータ|train+testデータ|
|---|---|---|---|
|100|![t_400_900_switch1_binary_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/1b53b15f-2a98-9c32-b169-d64b2d0d3261.jpeg)|![v_400_900_switch1_binary_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e04cdf35-a7bc-b3b2-cdf2-52a2e750f018.jpeg)|![a_400_900_switch1_binary_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9346835d-adea-a3b6-fc86-c31e6038403d.jpeg)|
|200|![t_400_900_switch1_binary_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/252cc341-ad15-021b-806c-9292ecd2802f.jpeg)|![v_400_900_switch1_binary_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/c97d2a43-fe64-6787-33bf-9ecf516dff03.jpeg)|![a_400_900_switch1_binary_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/dc955982-748e-9468-3bba-c44b4f5a175b.jpeg)|
|300|![t_400_900_switch1_binary_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9695de91-a83f-d159-2f38-e2e47d77db9d.jpeg)|![v_400_900_switch1_binary_300.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/499d97e6-c7c6-12cb-5c79-e72a471b7f3f.jpeg)|![400_900_switch1_binary_300_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8d144a43-4f30-c507-4d93-980992553028.jpeg)|
|400|![t_400_900_switch1_binary_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/c8710df5-c4f9-6080-7b14-ff810c0e6be2.jpeg)|![v_400_900_switch1_binary_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d1be8be9-ea66-9f73-7e66-ee287bd8de18.jpeg)|![a_400_900_switch1_binary_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/765db69c-984a-62fd-a523-cb2eedfca726.jpeg)|
|500|![t_400_900_switch1_binary_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/e8aab515-387e-b244-36fa-4d37353e4743.jpeg)|![v_400_900_switch1_binary_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/93a6aab2-7cf8-14d6-e9ca-539fe9b1a849.jpeg)|![a_400_900_switch1_binary_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/3fc8f5d2-557c-0b8a-4435-f6ae80858ed1.jpeg)|
|600|![t_400_900_switch1_binary_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/be8e568e-3908-d28f-7869-3e5672d9fe2b.jpeg)|![v_400_900_switch1_binary_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/6d694286-c124-55f4-a89d-db756493af11.jpeg)|![a_400_900_switch1_binary_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/da723a32-e361-e7d8-3ba6-6bd523a33321.jpeg)|
|700|![t_400_900_switch1_binary_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/22146fd2-a244-c9dd-2c7f-bbdf1f63e6ab.jpeg)|![v_400_900_switch1_binary_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/79125719-eb9f-813a-5723-1e1399adbc7c.jpeg)|![a_400_900_switch1_binary_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/93c8522c-3318-754c-a50f-64d4db13016d.jpeg)|
|800|![400_900_switch1_binary_800_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5c417926-d5ed-20f3-d1e0-85925b67041b.jpeg)|![400_900_switch1_binary_800_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/87305c2f-99e2-fd0c-13b4-6e5e95fbf0d1.jpeg)|![400_900_switch1_binary_800_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a47a4025-873b-23e7-f956-f77800baa02e.jpeg)|
|900|![400_900_switch1_binary_900_t.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/d94ef4a8-2ca3-9e46-3fe3-a7f508e05575.jpeg)|![400_900_switch1_binary_900_v.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/179f9ba9-09a1-35eb-f8f6-ef231cf09042.jpeg)|![400_900_switch1_binary_900_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fdfda674-8fe2-b443-4d5d-d689bca0eb9b.jpeg)|


※ 学習は二値分類問題として実施しましたが、各異常モードごとの差異がわかるように、推論とプロットは多クラスで行っています。

####考察
異常データを生成してデータ数を増やしているので、エポックあたりの学習時間も増加し、学習の進行も遅くなっています。（エポック400あたりで落ち着いて来ています。）
エポック900が最も精度がよさそうですが、特に他の手法と比べて優れているというわけでもなさそうです。
もう少し、学習を進めてみると面白いかも知れません。

###1000x1000の元画像を、400x900にクロップし、200x450に resize して、さらに、対象物（カプセル）の画像を部分的に入れ替えることで、異常画像を増やして、各異常モードごとの多クラス分類として実施


####データ

|元画像|加工後|
|---|---|
|![図4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/09a4d071-e6dc-8ee8-ed71-b4f6fdc398a0.png)|![図2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/dd680be2-02c8-4d8a-f620-247b4bf7d036.png)|
|![図3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9ae22c59-f7da-647b-b94d-e5e2f11d91cf.png)|![図5.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/0787206b-421b-fb99-2d45-d2febb0c591c.png)|

緑の枠線で囲った部分を左右入れ替えて、異常データを水増ししています。

|crack|imprint|poke|
|---|---|---|
|![400_900_switch1_1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/97b28158-5d03-a2d1-b48b-d6e5ef8a8a06.png)|![400_900_switch1_2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/fecb507e-7077-35ae-4e0a-1f492164f8d4.png)|![400_900_switch1_3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ed9748e2-6c8f-219f-6775-50143bec1ba2.png)|

|scratch|squeeze|
|---|---|
![400_900_switch1_4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/631bee0c-bd67-26d8-f350-9b9314ee961c.png)|![400_900_switch1_5.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/290ad1f4-9647-736a-9cc5-3557e79da0ba.png)|

####結果
|エポック数|trainデータ|testデータ|train+testデータ|
|---|---|---|---|
|100|![t_400_900_switch1_multi_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/eb59fdd9-635c-e8ca-9736-35a8c36d5f41.jpeg)|![v_400_900_switch1_multi_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/8ec38de1-fb36-5760-231c-cd117462c704.jpeg)|![a_400_900_switch1_multi_100.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/69f2dc3d-bfb0-41ac-9100-1df7cf022d17.jpeg)|
|200|![t_400_900_switch1_multi_200.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/43f272d8-6de1-a72e-64ff-76a7aa2f5a13.jpeg)|![v_400_900_switch1_multi_200 .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/3c849581-3747-b061-f0cc-a73180ca7512.jpeg)|![a_400_900_switch1_multi_200 .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/54c0658e-25d3-735b-e0e7-36bfffd3957b.jpeg)|
|300|![t_400_900_switch1_multi_300 .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/814ac433-864b-3a4d-5c04-aba3bcc03f72.jpeg)|![v_400_900_switch1_multi_300 .jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/b6e865dd-6ec0-aa91-7aff-967f7a6ad3d0.jpeg)|![400_900_switch1_multi_300_a.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/06ec9346-b6cb-ac42-7b41-5cb9024f2b35.jpeg)|
|400|![t_400_900_switch1_multi_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/9468e994-fd09-5882-1404-2d6bb9c84f5c.jpeg)|![v_400_900_switch1_multi_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/1efc07c4-4b8e-923e-d6c9-ce7f06697b67.jpeg)|![a_400_900_switch1_multi_400.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5c59831b-4414-e480-c1b6-53913f811221.jpeg)|
|500|![t_400_900_switch1_multi_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/a2a37436-7ef8-f753-38db-b3ddd5655346.jpeg)|![v_400_900_switch1_multi_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/f01c7776-432b-a4e6-0a30-dbaf3270d8c6.jpeg)|![a_400_900_switch1_multi_500.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ab8460c0-3f94-e795-db60-6136474be8d1.jpeg)|
|600|![t_400_900_switch1_multi_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/5b0f31b0-d2a0-816a-900d-7f50ba9b05c2.jpeg)|![v_400_900_switch1_multi_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/89fcf3ca-e97e-92f3-b950-8224de5929f3.jpeg)|![a_400_900_switch1_multi_600.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/ed2e612a-66ff-7d1a-f278-3fe32d742242.jpeg)|
|700|![t_400_900_switch1_multi_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/6ca713d2-466b-1bbe-aae0-c4a5c64c9259.jpeg)|![v_400_900_switch1_multi_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/4e92c427-de8c-ca1e-0e96-857306ff8f60.jpeg)|![a_400_900_switch1_multi_700.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/600629/050ad832-b9e0-41fa-5a07-433a7cbf9637.jpeg)|

####考察
異常データを生成してデータ数を増やしているので、エポックあたりの学習時間は増加していますが、学習の進行はかなり早く、エポック100ですでに落ち着きはじめています。
二値分類と多クラス分類で、どうしてこんなに差が出たのか分かりませんが、考えられるのは、二値分類としては、異常データに多様性がありすぎるが、多クラス分類としては、各異常モードごとの異常データが増えたために、異常を捉えやすくなったのかも知れません。
また、エポック500、600、700あたりでは、なかなかいい結果を出しています。


#総論
capsuleは、なかなか難しいデータセットでした。（それでも、カプセルの向き等が揃っているので、MVTec ADのなかでは、まだ簡単な方だという気がしますが。）
結果として、カプセル本体のある部分だけにトリミングをするというのが、最も効果的な前処理だと言うことが分かりました。
また、エポックが進むにつれて、学習がどのように進むのかを理解する非常にいい実験になりました。