SlideShare a Scribd company logo
1 of 13
Download to read offline
Pill Quality Control:
Classification &
GANs
Foundations of Deep Learning June 2022
Gaetano Chiriaco 882638
Gianmarco Russo 887277
Pill quality control dataset:
1. 225x225px RGB .jpg images
2. 3 different classes: normal, chip, dirt
3. Small dataset: 330 images
4. Unbalanced classes
Problem Outline
Normal
149 images
Chip
43 images
Dirt
138 images
Chosen Tasks:
1. Image Classification
2. Image Augmentation using classic
transformations and GANs
First Image classification
- Stratified splitting in Train (60%), Validation (20%) and Test (20%)
- Convolutional Neural Network architecture:
Other approaches used:
- Data augmentation using the aforementioned net (horizontal/vertical flip and
random rotation)
- Fine tuning of an imageNet pre-trained network (MobileNet)
Callbacks: EarlyStopping (patience=5) Loss: Categorical Cross-Entropy Optimizer: Adam (LR = 0.0001)
Results on the original dataset
When things go too well there’s
almost always something wrong…
F-Score Accuracy Precision Recall Loss
Our CNN
390,083 trainable
parameters
1 1 1 1 0.0193
MobileNet
1,865,283 trainable
parameters
0.979 0.971 0.979 0.979 0.0359
Our CNN results during the training
Our CNN does a perfect job on the test set
The models we trained have developed some biases: in particular the lighting
and the background of the images is different among the classes
Probably the model learns to distinguish between classes focusing on other aspects instead of the pill itself
#6d8b8bff #f3c4b0ff #587175ff #f7c6b8ff #525753ff #e7a390ff
Fixing the biases - I
Fixing the biases - II
The training process has been repeated with grayscale and masked images.
The objective was to eliminate the biases caused by the background and the lighting.
MobileNet was not usable at this point since it only works with RGB images, so we only used
our CNN, slightly tuning its architecture to work with grayscale images.
Python Library used: CV2
RGB GrayScale Without
background
Not all the images were perfectly
masked, so we removed 40
images that were badly cut
Results on altered images
F-Score Accuracy Precision Recall Loss
Class
Accuracy
CNN
on grayscale
images
0.989 0.9857 0.989 0.989 0.0568
Normal: 1
Dirt: 0.965
Chip: 1
CNN
on masked
images
0.769 0.787 0.835 0.718 0.5362
Normal: 0.9
Dirt: 0.79
Chip: 0.375
As we can see, the grayscale images
don’t fix the biases, showing the same
performance. However the masked one
definitely showed some signs of
change: the model can’t exploit the
background and the lighting and its
performance drops quite significantly.
Grayscale images Masked images
Generative Adversarial Neural Networks
GANs are generative models estimated via
an adversarial process, in which we
simultaneously train two models: a
generative model G that captures the data
distribution, and a discriminative model D
that estimates the probability that a
sample came from the training data rather
than G.
Used for various tasks like:
- Image augmentation
- Super resolution
- Style transfer
Loss function:
GANs architecture for image augmentation
Generator (1,861,723 trainable parameters)
Discriminator (1,224,777 trainable parameters)
Different model for each pill type
(normal, dirt, chip)
Different model for each image
type (RGB, grayscale, masked)
500 epochs for the “normal” class, 500
for the “dirt” class and 500 for the
“chip” class
Noise size: 100
Batch size: 16
Problems and disadvantages encountered:
- Complicated structure
- Needs usually a high number of epochs to output good (fake) images
- Mode Collapse
- Hard to evaluate the effectiveness
(7, 7, 224) (14, 14, 224) (28, 28, 112) (56, 56, 56) (112, 112, 28) (224, 224, 14) (224, 224, 3)
(112, 112, 28)
(100)
(224, 224, 3)
(56, 56, 56) (28, 28, 112) (14, 14, 224) (7, 7, 448) (21952) (1)
Normal Dirt Chip
RGB
(too many
epochs to get a
sufficient result)
Grayscale
Masked
(quality of
generated
images was
poor)
Last 200 epochs results
Normal
84 images
Chip
21 images
Dirt
68 images
+6 +9 +22
Normal
(GAN augmented)
90 images
Chip
(GAN augmented)
30 images
Dirt
(GAN augmented)
90 images
+60
Chip
(GAN augmented)
90 images
Initial dataset
After GAN
augmentation
After classic
augmentation
Data processing after GANs
Best GAN-generated images were
manually selected and masked
Masking
Comparing the performances
F-Score Accuracy Precision Recall Loss
Class
Accuracy
CNN
on augmented
masked
images
0.850 0.853 0.866 0.836 0.5326
Normal: 0.76
Dirt: 0.92
Chip: 1
CNN
on masked
images
0.769 0.787 0.835 0.718 0.5362
Normal: 0.9
Dirt: 0.79
Chip: 0.375
In this kind of problems the
accuracy on the “anomalous”
classes is really what matters
The new classifier didn’t achieve the performances of
the first CNN on RGB, but it’s trained on much simpler
images without the influence of colors and
backgrounds
Possible developments and
improvement
- Improve the masking process to avoid the removal of some of
the images
- Explore different and more complicated types of GAN to obtain
better results (like Conditional GANs)
- Solve the “Mode Collapse” issue
- Choose the best generation of images using more “formal”
approaches (like Inception Score)
- Enrich the initial dataset adding different type of pills
Pill Quality
Control:
Classification &
GANs
Foundations of Deep Learning June 2022
Gaetano Chiriaco 882638
Gianmarco Russo 887277
Thanks for your attention!
Bibliography:
1. Ian J. Goodfellow et al. “Generative Adversarial Networks” (2014)
2. Mehdi Mirza e Simon Osindero. “Conditional Generative Adversarial Nets” (2014)
Sitography:
1. Transfer learning with MobileNet (tensorflow.org)
2. GAN | Generate Your Own Dataset using Generative Adversarial Networks (analyticsvidhya.com)

More Related Content

Similar to PillQC-Deep-Learning

IMAGE DE-NOISING USING DEEP NEURAL NETWORK
IMAGE DE-NOISING USING DEEP NEURAL NETWORKIMAGE DE-NOISING USING DEEP NEURAL NETWORK
IMAGE DE-NOISING USING DEEP NEURAL NETWORKaciijournal
 
Yonsei Data Science Lab - Computer Vision
Yonsei Data Science Lab - Computer VisionYonsei Data Science Lab - Computer Vision
Yonsei Data Science Lab - Computer VisionDataScienceLab
 
Deep Learning in Computer Vision
Deep Learning in Computer VisionDeep Learning in Computer Vision
Deep Learning in Computer VisionSungjoon Choi
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image ProcessingAzharo7
 
Image classification
Image classificationImage classification
Image classificationAnchor Charan
 
Ultrasound Nerve Segmentation
Ultrasound Nerve Segmentation Ultrasound Nerve Segmentation
Ultrasound Nerve Segmentation Sneha Ravikumar
 
Week2- Deep Learning Intuition.pptx
Week2- Deep Learning Intuition.pptxWeek2- Deep Learning Intuition.pptx
Week2- Deep Learning Intuition.pptxfahmi324663
 
Designed by Identity MLP
Designed by Identity MLP Designed by Identity MLP
Designed by Identity MLP butest
 
ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)Hasitha Ediriweera
 
Learn to Build an App to Find Similar Images using Deep Learning- Piotr Teterwak
Learn to Build an App to Find Similar Images using Deep Learning- Piotr TeterwakLearn to Build an App to Find Similar Images using Deep Learning- Piotr Teterwak
Learn to Build an App to Find Similar Images using Deep Learning- Piotr TeterwakPyData
 
AISF19 - Unleash Computer Vision at the Edge
AISF19 - Unleash Computer Vision at the EdgeAISF19 - Unleash Computer Vision at the Edge
AISF19 - Unleash Computer Vision at the EdgeBill Liu
 
机器学习Adaboost
机器学习Adaboost机器学习Adaboost
机器学习AdaboostShocky1
 
[AI07] Revolutionizing Image Processing with Cognitive Toolkit
[AI07] Revolutionizing Image Processing with Cognitive Toolkit[AI07] Revolutionizing Image Processing with Cognitive Toolkit
[AI07] Revolutionizing Image Processing with Cognitive Toolkitde:code 2017
 
Pix4D quality report for July 21 2017 RGB of terraref.org sorghum at Maricopa...
Pix4D quality report for July 21 2017 RGB of terraref.org sorghum at Maricopa...Pix4D quality report for July 21 2017 RGB of terraref.org sorghum at Maricopa...
Pix4D quality report for July 21 2017 RGB of terraref.org sorghum at Maricopa...Rick Ward
 
Neural network image recognition
Neural network image recognitionNeural network image recognition
Neural network image recognitionOleksii Sekundant
 
Image orientation classification analysis
Image orientation classification analysisImage orientation classification analysis
Image orientation classification analysisRohit Dandona
 
Learning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and KaggleLearning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and KaggleYvonne K. Matos
 

Similar to PillQC-Deep-Learning (20)

IMAGE DE-NOISING USING DEEP NEURAL NETWORK
IMAGE DE-NOISING USING DEEP NEURAL NETWORKIMAGE DE-NOISING USING DEEP NEURAL NETWORK
IMAGE DE-NOISING USING DEEP NEURAL NETWORK
 
Yonsei Data Science Lab - Computer Vision
Yonsei Data Science Lab - Computer VisionYonsei Data Science Lab - Computer Vision
Yonsei Data Science Lab - Computer Vision
 
Deep Learning in Computer Vision
Deep Learning in Computer VisionDeep Learning in Computer Vision
Deep Learning in Computer Vision
 
Steganography Part 2
Steganography Part 2Steganography Part 2
Steganography Part 2
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
 
Image classification
Image classificationImage classification
Image classification
 
Ultrasound Nerve Segmentation
Ultrasound Nerve Segmentation Ultrasound Nerve Segmentation
Ultrasound Nerve Segmentation
 
IMAGE PROCESSING
IMAGE PROCESSINGIMAGE PROCESSING
IMAGE PROCESSING
 
Week2- Deep Learning Intuition.pptx
Week2- Deep Learning Intuition.pptxWeek2- Deep Learning Intuition.pptx
Week2- Deep Learning Intuition.pptx
 
Designed by Identity MLP
Designed by Identity MLP Designed by Identity MLP
Designed by Identity MLP
 
ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)
 
Learn to Build an App to Find Similar Images using Deep Learning- Piotr Teterwak
Learn to Build an App to Find Similar Images using Deep Learning- Piotr TeterwakLearn to Build an App to Find Similar Images using Deep Learning- Piotr Teterwak
Learn to Build an App to Find Similar Images using Deep Learning- Piotr Teterwak
 
AISF19 - Unleash Computer Vision at the Edge
AISF19 - Unleash Computer Vision at the EdgeAISF19 - Unleash Computer Vision at the Edge
AISF19 - Unleash Computer Vision at the Edge
 
机器学习Adaboost
机器学习Adaboost机器学习Adaboost
机器学习Adaboost
 
JPEG Image Compression
JPEG Image CompressionJPEG Image Compression
JPEG Image Compression
 
[AI07] Revolutionizing Image Processing with Cognitive Toolkit
[AI07] Revolutionizing Image Processing with Cognitive Toolkit[AI07] Revolutionizing Image Processing with Cognitive Toolkit
[AI07] Revolutionizing Image Processing with Cognitive Toolkit
 
Pix4D quality report for July 21 2017 RGB of terraref.org sorghum at Maricopa...
Pix4D quality report for July 21 2017 RGB of terraref.org sorghum at Maricopa...Pix4D quality report for July 21 2017 RGB of terraref.org sorghum at Maricopa...
Pix4D quality report for July 21 2017 RGB of terraref.org sorghum at Maricopa...
 
Neural network image recognition
Neural network image recognitionNeural network image recognition
Neural network image recognition
 
Image orientation classification analysis
Image orientation classification analysisImage orientation classification analysis
Image orientation classification analysis
 
Learning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and KaggleLearning Predictive Modeling with TSA and Kaggle
Learning Predictive Modeling with TSA and Kaggle
 

Recently uploaded

Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxMohammedJunaid861692
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023ymrp368
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 

Recently uploaded (20)

Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 

PillQC-Deep-Learning

  • 1. Pill Quality Control: Classification & GANs Foundations of Deep Learning June 2022 Gaetano Chiriaco 882638 Gianmarco Russo 887277
  • 2. Pill quality control dataset: 1. 225x225px RGB .jpg images 2. 3 different classes: normal, chip, dirt 3. Small dataset: 330 images 4. Unbalanced classes Problem Outline Normal 149 images Chip 43 images Dirt 138 images Chosen Tasks: 1. Image Classification 2. Image Augmentation using classic transformations and GANs
  • 3. First Image classification - Stratified splitting in Train (60%), Validation (20%) and Test (20%) - Convolutional Neural Network architecture: Other approaches used: - Data augmentation using the aforementioned net (horizontal/vertical flip and random rotation) - Fine tuning of an imageNet pre-trained network (MobileNet) Callbacks: EarlyStopping (patience=5) Loss: Categorical Cross-Entropy Optimizer: Adam (LR = 0.0001)
  • 4. Results on the original dataset When things go too well there’s almost always something wrong… F-Score Accuracy Precision Recall Loss Our CNN 390,083 trainable parameters 1 1 1 1 0.0193 MobileNet 1,865,283 trainable parameters 0.979 0.971 0.979 0.979 0.0359 Our CNN results during the training Our CNN does a perfect job on the test set
  • 5. The models we trained have developed some biases: in particular the lighting and the background of the images is different among the classes Probably the model learns to distinguish between classes focusing on other aspects instead of the pill itself #6d8b8bff #f3c4b0ff #587175ff #f7c6b8ff #525753ff #e7a390ff Fixing the biases - I
  • 6. Fixing the biases - II The training process has been repeated with grayscale and masked images. The objective was to eliminate the biases caused by the background and the lighting. MobileNet was not usable at this point since it only works with RGB images, so we only used our CNN, slightly tuning its architecture to work with grayscale images. Python Library used: CV2 RGB GrayScale Without background Not all the images were perfectly masked, so we removed 40 images that were badly cut
  • 7. Results on altered images F-Score Accuracy Precision Recall Loss Class Accuracy CNN on grayscale images 0.989 0.9857 0.989 0.989 0.0568 Normal: 1 Dirt: 0.965 Chip: 1 CNN on masked images 0.769 0.787 0.835 0.718 0.5362 Normal: 0.9 Dirt: 0.79 Chip: 0.375 As we can see, the grayscale images don’t fix the biases, showing the same performance. However the masked one definitely showed some signs of change: the model can’t exploit the background and the lighting and its performance drops quite significantly. Grayscale images Masked images
  • 8. Generative Adversarial Neural Networks GANs are generative models estimated via an adversarial process, in which we simultaneously train two models: a generative model G that captures the data distribution, and a discriminative model D that estimates the probability that a sample came from the training data rather than G. Used for various tasks like: - Image augmentation - Super resolution - Style transfer Loss function:
  • 9. GANs architecture for image augmentation Generator (1,861,723 trainable parameters) Discriminator (1,224,777 trainable parameters) Different model for each pill type (normal, dirt, chip) Different model for each image type (RGB, grayscale, masked) 500 epochs for the “normal” class, 500 for the “dirt” class and 500 for the “chip” class Noise size: 100 Batch size: 16 Problems and disadvantages encountered: - Complicated structure - Needs usually a high number of epochs to output good (fake) images - Mode Collapse - Hard to evaluate the effectiveness (7, 7, 224) (14, 14, 224) (28, 28, 112) (56, 56, 56) (112, 112, 28) (224, 224, 14) (224, 224, 3) (112, 112, 28) (100) (224, 224, 3) (56, 56, 56) (28, 28, 112) (14, 14, 224) (7, 7, 448) (21952) (1)
  • 10. Normal Dirt Chip RGB (too many epochs to get a sufficient result) Grayscale Masked (quality of generated images was poor) Last 200 epochs results Normal 84 images Chip 21 images Dirt 68 images +6 +9 +22 Normal (GAN augmented) 90 images Chip (GAN augmented) 30 images Dirt (GAN augmented) 90 images +60 Chip (GAN augmented) 90 images Initial dataset After GAN augmentation After classic augmentation Data processing after GANs Best GAN-generated images were manually selected and masked Masking
  • 11. Comparing the performances F-Score Accuracy Precision Recall Loss Class Accuracy CNN on augmented masked images 0.850 0.853 0.866 0.836 0.5326 Normal: 0.76 Dirt: 0.92 Chip: 1 CNN on masked images 0.769 0.787 0.835 0.718 0.5362 Normal: 0.9 Dirt: 0.79 Chip: 0.375 In this kind of problems the accuracy on the “anomalous” classes is really what matters The new classifier didn’t achieve the performances of the first CNN on RGB, but it’s trained on much simpler images without the influence of colors and backgrounds
  • 12. Possible developments and improvement - Improve the masking process to avoid the removal of some of the images - Explore different and more complicated types of GAN to obtain better results (like Conditional GANs) - Solve the “Mode Collapse” issue - Choose the best generation of images using more “formal” approaches (like Inception Score) - Enrich the initial dataset adding different type of pills
  • 13. Pill Quality Control: Classification & GANs Foundations of Deep Learning June 2022 Gaetano Chiriaco 882638 Gianmarco Russo 887277 Thanks for your attention! Bibliography: 1. Ian J. Goodfellow et al. “Generative Adversarial Networks” (2014) 2. Mehdi Mirza e Simon Osindero. “Conditional Generative Adversarial Nets” (2014) Sitography: 1. Transfer learning with MobileNet (tensorflow.org) 2. GAN | Generate Your Own Dataset using Generative Adversarial Networks (analyticsvidhya.com)