Answers.Body: <p>Indeed instead of relying on pre-trained models from natural image datasets such as ImageNet or COCO-2014, you should train a classification model as feature extractor specifically on your concerned breast cancer images with three classes (benign, normal, malignant) to compute a domain specific FID which is more popular as image generative models' evaluation metric than IS.</p>
  <p>If your dataset is not extremely large, start with a (ImageNet) pre-trained CNN model such as a ResNet which is an effective feature extractor and fine-tune it on your breast cancer dataset after preprocessing your images to a consistent size required by the chosen model. Then train the model to classify images into the above three classes by, say, the standard CE loss and save the trained model with the best performance of standard metrics like accuracy, F1-score, or ROC-AUC on the validation set. Finally extract feature embeddings from the penultimate layer of the trained model for both real and generated images to compute FID between the two types of embeddings via their respective mean and covariance statistics.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-30T03:36:28.717Z
Answers.LastActivityDate: 2024-11-30T03:36:28.717Z
Answers.UserDisplayName: cinch
Answers.Body: <p>Most metrics for evaluating generative models, including IS and FID, are indeed based on pre-trained feature extractors. Regarding the data where these features extractors are trained, I agree with cinch's <a href="https://ai.stackexchange.com/questions/47370/are-there-any-metrics-suitable-for-evaluating-conditional-gans-in-the-context-of/47371#47371">answer</a>: for specific domains, it is good practice to take a pre-trained feature detector and fine-tune it to your data.</p>
  <p>The way these feature extractors are trained has a major impact on the quality of the evaluation of generative models. For example, (1) found that Inception-based features are actually a bit lousy, and instead propose computing FID using embeddings from the CLIP (2) model, which in practice seem to be more informative. Similarly, other metrics such as (improved) Precision &amp; Recall (3) and Density &amp; Coverage (4) rely on embeddings from VGG-16 rather than InceptionV3.</p>
  <p>Moving on from the feature detector and on to the metrics themselves: the IS is rarely used nowadays as it is too easily swayed by small image perturbations. Indeed, state-of-the-art GAN papers rarely report the IS since it was shown to really not provide useful insight into the quality of a generative model (5).</p>
  <p>Speaking of Precision &amp; Recall and Density &amp; Coverage: precision/density approximate how much of the learned manifold overlaps with the data manifold (i.e., how much the generated data looks like the real data). On the other hand, recall/coverage try to measure how much of the real data distribution is captured by the generative model (i.e., how much of the data our model can generate).</p>
  <p>Without getting into too many details (check the papers for those), Density &amp; Coverage came as an &quot;improvement&quot; - or follow-up - to Precision &amp; Recall: it is less sensitive to outliers and is more efficient to compute. However, it may still make sense to evaluate a model using P&amp;R for at least these two reasons:</p>
  <ul>
  <li>It still seems to be more widely reported (popular?) than Density &amp; Coverage, so for consistency in the literature it is still probably a good idea to report it.</li>
  <li>While Precision is bounded between 0 and 1, that is not the case for Density, which is unbounded above; therefore, you may argue that Precision is more easily interpretable.</li>
  </ul>
  <p>Some other metrics that may be of interest to you:</p>
  <ul>
  <li>Class-Aware Fréchet Distance (6), which argues that the single-manifold Gaussian assumption made in FID may lose class information on labeled datasets. They use specialized feature detectors trained on specific domain data. However, this metric is for unconditional models.</li>
  <li>Intra-FID, first used in (7), reports the mean of the FIDs calculated separately for each class.</li>
  <li>Kernel Inception Distance (8), where the authors argue that FID can be biased when the data is small. The KID is unbiased by design. However, it is usually very correlated with FID and is not very commonly reported.</li>
  </ul>
  <p>My <strong>advice</strong>: default to tracking FID (with CLIP features) and either P&amp;R or D&amp;C during training, and check within your specific literature niche if there are other relevant metrics. When reporting results, it's not a bad idea to evaluate your models on as many (within reason) metrics as possible, even if they end up in the appendix.</p>
  <hr />
  <p>References:</p>
  <p>(1) - Kynkäänniemi, T., Karras, T., Aittala, M., Aila, T., &amp; Lehtinen, J. (2022). The role of imagenet classes in fréchet inception distance. <em>arXiv preprint arXiv:2203.06026</em>.</p>
  <p>(2) - Radford, A., Kim, J. W., Hallacy, C., Ramesh, A., Goh, G., Agarwal, S., ... &amp; Sutskever, I. (2021, July). Learning transferable visual models from natural language supervision. In <em>International conference on machine learning</em> (pp. 8748-8763). PMLR.</p>
  <p>(3) - Kynkäänniemi, T., Karras, T., Laine, S., Lehtinen, J., &amp; Aila, T. (2019). Improved precision and recall metric for assessing generative models. <em>Advances in neural information processing systems</em>, 32.</p>
  <p>(4) - Naeem, M. F., Oh, S. J., Uh, Y., Choi, Y., &amp; Yoo, J. (2020, November). Reliable fidelity and diversity metrics for generative models. In <em>International Conference on Machine Learning</em> (pp. 7176-7185). PMLR.</p>
  <p>(5) - Barratt, S., &amp; Sharma, R. (2018). A note on the inception score. <em>arXiv preprint arXiv:1801.01973</em>.</p>
  <p>(6) - Liu, S., Wei, Y., Lu, J., &amp; Zhou, J. (2018). An improved evaluation framework for generative adversarial networks. <em>arXiv preprint arXiv:1803.07474</em>.</p>
  <p>(7) - Miyato, T., &amp; Koyama, M. (2018). cGANs with projection discriminator. <em>arXiv preprint arXiv:1802.05637</em>.</p>
  <p>(8) - Bińkowski, M., Sutherland, D. J., Arbel, M., &amp; Gretton, A. (2018). Demystifying mmd gans. <em>arXiv preprint arXiv:1801.01401</em>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-03T11:19:00.520Z
Answers.LastActivityDate: 2024-12-03T11:19:00.520Z
Answers.UserDisplayName: Saucy Goat
Body: <p>I am currently training a conditional GAN for breast cancer images with three classes: benign, normal, and malignant. While researching evaluation methods, I found that GANs are commonly assessed using metrics like the Inception Score (IS) or the Fréchet Inception Distance (FID). However, as I understand it, these metrics rely on the pre-trained Inception V3 model, which was trained on natural images and may not perform well for medical images. This often results in low scores, even if the generated images are of good quality.</p>
  <p>Given this limitation, are there any metrics suitable for evaluating conditional GANs in the context of medical imaging?</p>
  <p>Ideally, I am looking for metrics that consider both the diversity of the generated images and their distinctiveness (similar to what the Inception Score measures).</p>
  
Tags: <computer-vision><reference-request><generative-adversarial-networks><metric><conditional-gan>
Title: Are there any metrics suitable for evaluating conditional GANs in the context of medical imaging?
UserDisplayName: Eliza Romanski
ThreadText: # Are there any metrics suitable for evaluating conditional GANs in the context of medical imaging?
  
  (Asked by: username_0 on 2024-11-30)
  
  I am currently training a conditional GAN for breast cancer images with three classes: benign, normal, and malignant. While researching evaluation methods, I found that GANs are commonly assessed using metrics like the Inception Score (IS) or the Fréchet Inception Distance (FID). However, as I understand it, these metrics rely on the pre-trained Inception V3 model, which was trained on natural images and may not perform well for medical images. This often results in low scores, even if the generated images are of good quality.
  
  Given this limitation, are there any metrics suitable for evaluating conditional GANs in the context of medical imaging?
  
  Ideally, I am looking for metrics that consider both the diversity of the generated images and their distinctiveness (similar to what the Inception Score measures).
  
  **Tags:** computer-vision, reference-request, generative-adversarial-networks, metric, conditional-gan
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2024-11-30. Score: 2
  
  Indeed instead of relying on pre-trained models from natural image datasets such as ImageNet or COCO-2014, you should train a classification model as feature extractor specifically on your concerned breast cancer images with three classes (benign, normal, malignant) to compute a domain specific FID which is more popular as image generative models' evaluation metric than IS.
  
  If your dataset is not extremely large, start with a (ImageNet) pre-trained CNN model such as a ResNet which is an effective feature extractor and fine-tune it on your breast cancer dataset after preprocessing your images to a consistent size required by the chosen model. Then train the model to classify images into the above three classes by, say, the standard CE loss and save the trained model with the best performance of standard metrics like accuracy, F1-score, or ROC-AUC on the validation set. Finally extract feature embeddings from the penultimate layer of the trained model for both real and generated images to compute FID between the two types of embeddings via their respective mean and covariance statistics.
  
  
  ---
  
  ### Answer by username_2 on 2024-12-03. Score: 1
  
  Most metrics for evaluating generative models, including IS and FID, are indeed based on pre-trained feature extractors. Regarding the data where these features extractors are trained, I agree with cinch's [answer](https://ai.stackexchange.com/questions/47370/are-there-any-metrics-suitable-for-evaluating-conditional-gans-in-the-context-of/47371#47371): for specific domains, it is good practice to take a pre-trained feature detector and fine-tune it to your data.
  
  The way these feature extractors are trained has a major impact on the quality of the evaluation of generative models. For example, (1) found that Inception-based features are actually a bit lousy, and instead propose computing FID using embeddings from the CLIP (2) model, which in practice seem to be more informative. Similarly, other metrics such as (improved) Precision & Recall (3) and Density & Coverage (4) rely on embeddings from VGG-16 rather than InceptionV3.
  
  Moving on from the feature detector and on to the metrics themselves: the IS is rarely used nowadays as it is too easily swayed by small image perturbations. Indeed, state-of-the-art GAN papers rarely report the IS since it was shown to really not provide useful insight into the quality of a generative model (5).
  
  Speaking of Precision & Recall and Density & Coverage: precision/density approximate how much of the learned manifold overlaps with the data manifold (i.e., how much the generated data looks like the real data). On the other hand, recall/coverage try to measure how much of the real data distribution is captured by the generative model (i.e., how much of the data our model can generate).
  
  Without getting into too many details (check the papers for those), Density & Coverage came as an "improvement" - or follow-up - to Precision & Recall: it is less sensitive to outliers and is more efficient to compute. However, it may still make sense to evaluate a model using P&R for at least these two reasons:
  
  * It still seems to be more widely reported (popular?) than Density & Coverage, so for consistency in the literature it is still probably a good idea to report it.
  * While Precision is bounded between 0 and 1, that is not the case for Density, which is unbounded above; therefore, you may argue that Precision is more easily interpretable.
  
  Some other metrics that may be of interest to you:
  
  * Class-Aware Fréchet Distance (6), which argues that the single-manifold Gaussian assumption made in FID may lose class information on labeled datasets. They use specialized feature detectors trained on specific domain data. However, this metric is for unconditional models.
  * Intra-FID, first used in (7), reports the mean of the FIDs calculated separately for each class.
  * Kernel Inception Distance (8), where the authors argue that FID can be biased when the data is small. The KID is unbiased by design. However, it is usually very correlated with FID and is not very commonly reported.
  
  My **advice**: default to tracking FID (with CLIP features) and either P&R or D&C during training, and check within your specific literature niche if there are other relevant metrics. When reporting results, it's not a bad idea to evaluate your models on as many (within reason) metrics as possible, even if they end up in the appendix.
  
  ---
  
  References:
  
  (1) - Kynkäänniemi, T., Karras, T., Aittala, M., Aila, T., & Lehtinen, J. (2022). The role of imagenet classes in fréchet inception distance. *arXiv preprint arXiv:2203.06026*.
  
  (2) - Radford, A., Kim, J. W., Hallacy, C., Ramesh, A., Goh, G., Agarwal, S., ... & Sutskever, I. (2021, July). Learning transferable visual models from natural language supervision. In *International conference on machine learning* (pp. 8748-8763). PMLR.
  
  (3) - Kynkäänniemi, T., Karras, T., Laine, S., Lehtinen, J., & Aila, T. (2019). Improved precision and recall metric for assessing generative models. *Advances in neural information processing systems*, 32.
  
  (4) - Naeem, M. F., Oh, S. J., Uh, Y., Choi, Y., & Yoo, J. (2020, November). Reliable fidelity and diversity metrics for generative models. In *International Conference on Machine Learning* (pp. 7176-7185). PMLR.
  
  (5) - Barratt, S., & Sharma, R. (2018). A note on the inception score. *arXiv preprint arXiv:1801.01973*.
  
  (6) - Liu, S., Wei, Y., Lu, J., & Zhou, J. (2018). An improved evaluation framework for generative adversarial networks. *arXiv preprint arXiv:1803.07474*.
  
  (7) - Miyato, T., & Koyama, M. (2018). cGANs with projection discriminator. *arXiv preprint arXiv:1802.05637*.
  
  (8) - Bińkowski, M., Sutherland, D. J., Arbel, M., & Gretton, A. (2018). Demystifying mmd gans. *arXiv preprint arXiv:1801.01401*.
  
  
  ---
  
  