2.Main idea about AnoGAN

#1 Introduction 
1. **limitation**: relying on the known markers.
2. **the benefit of using GAN**: GAN can solve the central problem of creating a sufficiently representative model of appearance while learning a generative and discriminative component
3. **Contribution**: Propose adversarial training of a generative model of normal appearance, a coupled mapping schema enables the evaluation of novel data to identify anomalous images.
4.  
 ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/623932/ac37e72e-5a2a-3372-4e31-d8d22e8cb98c.png)

#2 Generative Adversarial Representation Learning
- How to build a model
- How to use a model to identify appearance not present in the training data

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/623932/3896de35-c523-4dd9-500c-84df4910971f.png)
###2.1 Unsupervised Manifold Learning of Normal Anatomical Variability
- **Generator**: learn a distribution over data x 
- **Discriminator**: maps an image to a single scalar value, outputting the probability that the given input is a real image or an image generated by the generator

The value function:
$$
\underset G{min}\;\underset D{max}\;V\;(D,\;G)\;=\;E_{x\sim pdata}(x)\;\lbrack\log\;D(x)\rbrack\;+\;E_{z\sim pz(z)}\;\lbrack\log(1-D(G(z)))\rbrack\;
$$

During the training process, the generator improves in generating realistic images and the discriminator progressed in identifying real and fake images.

###2.2 Mapping new Images to the latent Space
**Prerequisite knowledge**: The latent space has a smooth transition, so sampling from two points close in the latent space generates two visually similar images

A loss function comprises two components: Residual loss and Discrimination loss

1.**Residual Loss**
The residual loss measures the visual dissimilarity between query image x and generated image, for an ideal normal query case, the residual loss is zero.
$$
L_R(z_\tau)\;=\;\underset\;{\sum\vert x-G(z_\tau)\vert}
$$   

2.**Discrimination Loss**
The labeled data are not used for training, so the author uses the idea of feature matching to improve the mapping to the latent space, which will provide a richer intermediate feature representation. So the discriminator used in this paper acts as a feature extractor rather than classifier
$$
L_D(z_\tau)\;=\;\underset\;{\sum\vert f(x)-f(G(z_\tau))\vert}
$$

The overall loss defined as:
$$
L(z_\tau)\;=\;(1-\;\lambda)\;\cdot\;L_D(z_\tau)\;+\;\lambda\;\cdot\;L_D(z_\tau)
$$
 
###2.3 Detection of Anomalies
An anomaly score can be directly derived from the mapping loss function:
$$
A(x)\;=\;\;(1-\;\lambda)\;\cdot R(x)\;+\;\lambda\cdot D(x)
$$

A small anomaly score means that a very similar image was already found.


#3 Result
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/623932/ade76887-42ce-2c57-a9f7-e013926b7cff.png)

- First row: real input images
- second row: generated by the model
- Third row: residual overlay

The result shows that:
**1.**The model is able to generate images(in the case of normal image), which is similar to the query images(input images). While the input image is anomalous images, the model will generate the image shows obvious intensity differences


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/623932/36b923e0-2fb6-0303-8843-5c2dd484fd3c.png)
**2.** 
Compared with AnoGAN, the aCAEs show worse performance to detect anomaly detection task. Compared with the original definition of the discrimination loss function, the loss function proposed by the author is better because the scores for the detection of anomalies are directly related to the losses for the mapping to latent space

#4 Pros and Cons

**Pros**

- The model can identify the anomalies on unseen data based on unsupervised training of a model on normal data
- The model shows good sensitivity and the capability to segment anomalies
- The utilization of residual loss alone shows good results for mapping from image to the latent space


# Reference
Schlegl, Waldstein: Unsupervised anomaly detection with generative adversarial networks to guide marker discovery. Lecture Notes in Computer Science 10265 LNCS, 146-147(2017)