Transfer Learning CNN
Transfer Learning CNN
Transfer learning is a machine learning technique where a pre-trained model is used as a starting point for a new task. In the
context of convolutional neural networks (CNNs), this means using a CNN that has been trained on a large dataset for one task
(e.g., ImageNet) as a foundation for a new task (e.g., classifying medical images).
Reduced Training Time: Training a CNN from scratch on a large dataset can be computationally expensive and time-consuming.
Transfer learning allows you to leverage the knowledge learned by the pre-trained model, reducing training time significantly.
Improved Performance: Pre-trained models have often been trained on massive datasets, allowing them to learn general-purpose
features that can be useful for a wide range of tasks. Using these pre-trained models can improve the performance of your new task.
Smaller Datasets: Transfer learning can be particularly useful when you have a small dataset for your new task. By using a pre-
trained model, you can augment your limited data with the knowledge learned from the larger dataset.
Choose a Pre-trained Model: Select a pre-trained CNN that is suitable for your task. Common choices include VGG16, ResNet,
InceptionV3, and EfficientNet.
Freeze Layers: Typically, the earlier layers of a CNN learn general-purpose features, while the later layers learn more task-specific
features. You can freeze the earlier layers of the pre-trained model to prevent them from being updated during training. This helps to
preserve the learned features.
Add New Layers: Add new layers, such as fully connected layers or convolutional layers, to the end of the pre-trained model. These
layers will be trained on your new dataset to learn task-specific features.
Fine-tune: Train the new layers on your dataset while keeping the frozen layers fixed. This process is called fine-tuning.
Feature Extraction: Extract features from the pre-trained model and use them as input to a different model, such as a support
vector machine (SVM) or a random forest.
Fine-tuning: Fine-tune the pre-trained model on your new dataset to adapt it to your specific task.
Hybrid Approach: Combine feature extraction and fine-tuning by extracting features from the pre-trained model and using them as
input to a new model, while also fine-tuning some layers of the pre-trained model.
Transfer learning is a powerful technique that can significantly improve the performance and efficiency of CNNs, especially
when working with limited datasets or time constraints.
import numpy as np
import pandas as pd
# Visualization
import matplotlib.pyplot as plt
import seaborn as sns
# Keras library
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout, GlobalAveragePooling2D
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from keras.utils import to_categorical
from tensorflow.keras.callbacks import EarlyStopping
from keras import regularizers
from keras.callbacks import ReduceLROnPlateau
# Distributed Computing
import tensorflow as tf
import warnings
warnings.filterwarnings("ignore")
BATCH_SIZE = 48
image_height = 299
image_width = 299
data_generator_2 = ImageDataGenerator(
rescale=1./255,
rotation_range=10,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.1,
zoom_range=0.1,
brightness_range = [0.9,1.1],
horizontal_flip=False,
vertical_flip=False,
fill_mode='nearest'
)
print('Data Augmentation 2 was created')
train_generator1 = data_generator_1.flow_from_directory(
directory = "/kaggle/input/brain-tumor-classification-mri/Training",
color_mode = "rgb",
target_size = (image_height, image_width), # image height , image width
class_mode = "categorical",
batch_size = BATCH_SIZE,
shuffle = True,
seed = 42)
test_generator = data_generator_3.flow_from_directory(
directory = "/kaggle/input/brain-tumor-classification-mri/Testing",
color_mode = "rgb",
target_size = (image_height, image_width), # image height , image width
class_mode = "categorical",
batch_size = BATCH_SIZE,
shuffle = True,
seed = 42)
dict_class = train_generator1.class_indices
print('Dictionary: {}'.format(dict_class))
class_names = list(dict_class.keys()) # storing class/breed names in a list
print('Class labels: {}'.format(class_names))
# Dataset characteristics
print("Dataset Characteristics of Test Data Set:\n")
print("Number of images:", len(test_generator.classes))
print("Number of glioma_tumor images:", len([label for label in test_generator.classes if label == 0]))
print("Number of meningioma_tumor images:", len([label for label in test_generator.classes if label == 1]))
print("Number of no_tumor images:", len([label for label in test_generator.classes if label == 2]))
print("Number of pituitary_tumor images:", len([label for label in test_generator.classes if label == 3]))
print()
{0: 0.8686440677966102,
1: 0.8728710462287105,
2: 1.8164556962025316,
3: 0.8675937122128174}
plt.figure(figsize=[20, 15])
for i in range(15):
plt.subplot(3, 5, i+1)
plt.imshow(img[i])
plt.axis('off')
plt.title(class_names[np.argmax(label[i])])
plt.show()
# For development purpose, we first limit the train data set to the original image data set
# train_data = merged_train_generator
# train_data = train_generator1
train_data = train_generator1
# train_data = test_generator
VGG16
VGG16 is a convolutional neural network (CNN) architecture that was introduced in 2014. It was developed by researchers from
the University of Oxford and is known for its simplicity and effectiveness in image classification tasks.
Simple Architecture: VGG16 uses a stack of 16 convolutional layers, followed by three fully connected layers and a final softmax
layer for classification.
Small Filters: The convolutional layers in VGG16 use small 3x3 filters, which are repeated multiple times to increase the depth of
the network.
Uniform Stride: The convolutional layers use a uniform stride of 1, which means that the filters are applied to every pixel in the input
image.
Max Pooling: After each block of convolutional layers, a max pooling layer is used to reduce the spatial dimensions of the feature
maps.
Benefits of VGG16:
Simplicity: VGG16's architecture is relatively simple and easy to understand, making it a popular choice for researchers and
practitioners.
Effectiveness: VGG16 achieved state-of-the-art performance on the ImageNet classification dataset when it was introduced,
demonstrating its effectiveness in image classification tasks.
Pre-trained Models: Pre-trained VGG16 models are widely available, which can be used as a starting point for transfer learning
tasks in other domains.
Applications of VGG16:
Image Classification: VGG16 is commonly used for image classification tasks, such as object recognition, scene classification, and
facial recognition.
Transfer Learning: VGG16 can be used as a feature extractor for transfer learning tasks, where the pre-trained model is fine-tuned
on a smaller dataset to solve a related task.
Object Detection: VGG16 has been used as a component of object detection architectures, such as Faster R-CNN and SSD.
In summary, VGG16 is a powerful and versatile CNN architecture that has made significant contributions to the field of
computer vision. Its simplicity, effectiveness, and availability of pre-trained models make it a popular choice for various image
classification and transfer learning tasks.
# Create a MirroredStrategy
strategy = tf.distribute.MirroredStrategy(devices=['/gpu:0', '/gpu:1'])
# Open a strategy scope
with strategy.scope():
# Load the pre-trained VGG16 model without the top classification layer
base_model_VGG16 = VGG16(weights='imagenet', include_top=False, input_shape=(image_height, image_width, 3))
# Model summary
print("Model Summary (VGG16):")
model_VGG16.summary()
print()
MobileNetV2
MobileNetV2 is a convolutional neural network (CNN) architecture designed specifically for mobile and embedded vision
applications. It was introduced in 2018 and is known for its high efficiency and accuracy.
Benefits of MobileNetV2:
High Efficiency: MobileNetV2 is designed to be highly efficient, making it suitable for mobile and embedded devices with limited
computational resources.
High Accuracy: Despite its efficiency, MobileNetV2 achieves state-of-the-art accuracy on a variety of image classification
benchmarks.
Transfer Learning: MobileNetV2 can be used for transfer learning, where the pre-trained model is fine-tuned on a smaller dataset to
solve a related task.
Applications of MobileNetV2:
Mobile Vision: MobileNetV2 is widely used in mobile vision applications, such as object detection, image classification, and facial
recognition.
Embedded Vision: MobileNetV2 can be deployed on embedded devices, such as drones and robots, for tasks like real-time object
tracking and scene understanding.
Edge Computing: MobileNetV2 is well-suited for edge computing applications, where models are deployed on devices at the edge
of the network to reduce latency and bandwidth requirements.
In summary, MobileNetV2 is a highly efficient and accurate CNN architecture that is specifically designed for mobile and
embedded vision applications. Its inverted residual blocks, depthwise separable convolutions, and pointwise convolutions
make it a popular choice for developers working on resource-constrained devices.
%%time
# Create a MirroredStrategy
strategy = tf.distribute.MirroredStrategy(devices=['/gpu:0', '/gpu:1'])
# Load the pre-trained MobileNetV2 model without the top classification layer
base_model_MobileNet = MobileNetV2(weights='imagenet', include_top=False, input_shape=(image_height, image_width
# Add a global average pooling layer and output layer for classification
model_MobileNet.add(GlobalAveragePooling2D())
model_MobileNet.add(Dense(128, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_MobileNet.add(Dropout(0.4))
model_MobileNet.add(Dense(64, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_MobileNet.add(Dropout(0.2))
model_MobileNet.add(Dense(4, activation='softmax'))
# Model summary
print("Model Summary (MobileNetV2):")
model_MobileNet.summary()
print()
DenseNet
DenseNet, introduced in 2017, is a convolutional neural network (CNN) architecture known for its efficient use of parameters
and its ability to achieve high accuracy with relatively fewer layers. Unlike traditional CNNs, where each layer's output is
passed to the next layer, DenseNet connects every layer to every other layer after it. This dense connectivity pattern enhances
information flow and gradient propagation, leading to improved performance.
1. Dense Connectivity:
3. Transition Layers:
- Transition layers are used to reduce the number of feature maps and the spatial dimensions
of the network.
- They typically consist of a batch normalization layer, a 1x1 convolution, and a 2x2 average
pooling layer.
Benefits of DenseNet:
Efficient Parameter Usage: DenseNet can achieve high accuracy with fewer parameters compared to traditional CNNs.
Improved Information Flow: The dense connectivity pattern helps to propagate information more effectively through the network,
leading to better gradient flow and reduced vanishing gradient problems.
Feature Reuse: Features from earlier layers are reused by later layers, which can help to improve the network's ability to learn
complex patterns.
Reduced Overfitting: The dense connectivity pattern can help to reduce overfitting by encouraging feature reuse and preventing the
network from learning redundant features.
Applications of DenseNet:
Image Classification: DenseNet has been successfully used for various image classification tasks, such as ImageNet classification
and fine-grained object recognition.
Object Detection: DenseNet has been incorporated into object detection architectures like Faster R-CNN and SSD.
Semantic Segmentation: DenseNet has been applied to semantic segmentation tasks, where the goal is to assign a semantic label
to each pixel in an image.
In conclusion, DenseNet is a powerful and efficient CNN architecture that has made significant contributions to the field of
computer vision. Its dense connectivity pattern and efficient parameter usage make it a popular choice for various image
analysis tasks.
%%time
# Create a MirroredStrategy
strategy = tf.distribute.MirroredStrategy(devices=['/gpu:0', '/gpu:1'])
# Load the pre-trained DenseNet121 model without the top classification layer
base_model_DenseNet = DenseNet121(weights='imagenet', include_top=False, input_shape=(image_height, image_width
# Add a global average pooling layer and output layer for classification
model_DenseNet.add(GlobalAveragePooling2D())
model_DenseNet.add(Dense(128, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_DenseNet.add(Dropout(0.4))
model_DenseNet.add(Dense(64, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_DenseNet.add(Dropout(0.2))
model_DenseNet.add(Dense(4, activation='softmax'))
# Model summary
print("Model Summary (DenseNet121):")
model_DenseNet.summary()
print()
InceptionV3
InceptionV3 is a convolutional neural network (CNN) architecture introduced in 2015 that is known for its depth, width, and
computational efficiency. It builds upon the ideas of the Inception modules introduced in earlier Inception versions,
incorporating several enhancements to improve performance.
Inception Modules: The core building block of InceptionV3 is the Inception module. It consists of a parallel combination of different
convolutional filters with different sizes (1x1, 3x3, 5x5) and a pooling layer. This allows the network to capture features at different
scales.
Factorization: InceptionV3 uses a factorization technique to decompose 5x5 convolutions into two 3x3 convolutions. This reduces
the computational cost while maintaining performance.
Label Smoothing: To regularize the network and prevent overfitting, InceptionV3 uses label smoothing. This technique assigns a
small probability to incorrect classes, forcing the network to be less confident in its predictions.
Auxiliary Classifiers: To improve training stability, InceptionV3 includes auxiliary classifiers at intermediate layers. These classifiers
help to guide the training process, especially in the early stages.
Benefits of InceptionV3:
High Accuracy: InceptionV3 has achieved state-of-the-art performance on various image classification benchmarks, including
ImageNet.
Computational Efficiency: The factorization technique and auxiliary classifiers help to improve the computational efficiency of the
network.
Flexibility: The Inception modules allow the network to capture features at different scales, making it more flexible and adaptable to
various image tasks.
Applications of InceptionV3:
Image Classification: InceptionV3 is widely used for image classification tasks, such as object recognition, scene classification, and
fine-grained categorization.
Object Detection: InceptionV3 has been incorporated into object detection architectures like Faster R-CNN and SSD.
Semantic Segmentation: InceptionV3 has been applied to semantic segmentation tasks, where the goal is to assign a semantic
label to each pixel in an image.
In conclusion, InceptionV3 is a powerful and efficient CNN architecture that has made significant contributions to the field of
computer vision. Its Inception modules, factorization techniques, and auxiliary classifiers make it a popular choice for various
image analysis tasks.
%%time
# Create a MirroredStrategy
strategy = tf.distribute.MirroredStrategy(devices=['/gpu:0', '/gpu:1'])
# Load the pre-trained InceptionV3 model without the top classification layer
base_model_Inception = InceptionV3(weights='imagenet', include_top=False, input_shape=(image_height, image_width
# Add a global average pooling layer and output layer for classification
model_Inception.add(GlobalAveragePooling2D())
model_Inception.add(Dense(128, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_Inception.add(Dropout(0.4))
model_Inception.add(Dense(64, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_Inception.add(Dropout(0.2))
model_Inception.add(Dense(4, activation='softmax'))
# Model summary
print("Model Summary (InceptionV3):")
model_Inception.summary()
print()
ResNet
ResNet
ResNet (Residual Network), introduced in 2015, is a type of convolutional neural network (CNN) architecture that has
significantly impacted the field of deep learning. The key innovation in ResNet is the introduction of residual blocks, which
allow the network to learn residual functions instead of the entire underlying mapping. This enables the training of extremely
deep networks without suffering from the vanishing gradient problem.
Residual Blocks:
Identity Mapping: A residual block consists of a stack of layers followed by an identity connection. This identity connection allows
the network to bypass the stack of layers and directly pass the input to the output.
Residual Function: The residual function is the difference between the output of the stack of layers and the input. This residual
function is learned by the network.
Vanishing Gradient Problem: Residual blocks help to alleviate the vanishing gradient problem, which occurs when gradients
become very small during backpropagation, making it difficult for the network to learn. The identity connection provides a direct path
for gradients to flow, ensuring that they don't vanish completely.
Easier Optimization: Residual blocks make it easier for the network to learn deep representations. By learning the residual function,
the network can focus on learning the differences between the input and output, rather than the entire mapping.
Benefits of ResNet:
Deep Networks: ResNet has enabled the training of extremely deep networks, which have been shown to improve performance on
various tasks.
Improved Accuracy: ResNet has achieved state-of-the-art performance on many image classification benchmarks, such as
ImageNet.
Faster Training: Residual blocks can help to speed up training by making it easier for the network to learn deep representations.
Applications of ResNet:
Image Classification: ResNet is widely used for image classification tasks, such as object recognition and scene classification.
Object Detection: ResNet has been incorporated into object detection architectures like Faster R-CNN and SSD.
Semantic Segmentation: ResNet has been applied to semantic segmentation tasks, where the goal is to assign a semantic label to
each pixel in an image.
In conclusion, ResNet is a powerful and influential CNN architecture that has enabled the training of extremely deep networks
and has achieved state-of-the-art performance on various tasks. The introduction of residual blocks has been a major
breakthrough in deep learning, allowing for the development of more complex and accurate models.
%%time
import tensorflow as tf
from tensorflow.keras.applications import ResNet50
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout
from tensorflow.keras import regularizers
# Create a MirroredStrategy
strategy = tf.distribute.MirroredStrategy(devices=['/gpu:0', '/gpu:1'])
# Load the pre-trained ResNet50 model without the top classification layer
base_model_ResNet = ResNet50(weights='imagenet', include_top=False, input_shape=(image_height, image_width,
# Add a global average pooling layer and output layer for classification
model_ResNet.add(GlobalAveragePooling2D())
model_ResNet.add(Dense(128, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_ResNet.add(Dropout(0.4))
model_ResNet.add(Dense(64, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_ResNet.add(Dropout(0.2))
model_ResNet.add(Dense(4, activation='softmax'))
# Model summary
print("Model Summary (ResNet50):")
model_ResNet.summary()
print()
EfficientNet
EfficientNet is a family of convolutional neural network (CNN) architectures designed to achieve state-of-the-art accuracy with
significantly fewer computational resources compared to previous models. It introduces a novel scaling method that uniformly
scales the network's depth, width, and resolution.
Compound Scaling: EfficientNet uses a compound scaling method that scales the network's depth, width, and resolution in a
balanced manner. This ensures that the network's performance improves while maintaining computational efficiency.
EfficientNet-B0 to EfficientNet-B7: The EfficientNet family consists of a series of models, ranging from EfficientNet-B0 to
EfficientNet-B7. These models differ in their size and complexity, allowing for a trade-off between accuracy and computational cost.
MobileNetV2 Building Blocks: EfficientNet is based on MobileNetV2 building blocks, which are highly efficient and effective for
mobile and embedded vision applications.
Benefits of EfficientNet:
High Accuracy: EfficientNet achieves state-of-the-art accuracy on various image classification benchmarks, often surpassing
previous models with significantly fewer parameters.
Computational Efficiency: EfficientNet is designed to be computationally efficient, making it suitable for deployment on resource-
constrained devices.
Scalability: The compound scaling method allows EfficientNet to be easily scaled to different sizes and complexities, providing
flexibility for various applications.
Applications of EfficientNet:
Image Classification: EfficientNet is widely used for image classification tasks, such as object recognition, scene classification, and
fine-grained categorization.
Object Detection: EfficientNet has been incorporated into object detection architectures like Faster R-CNN and SSD.
Semantic Segmentation: EfficientNet has been applied to semantic segmentation tasks, where the goal is to assign a semantic
label to each pixel in an image.
In conclusion, EfficientNet is a powerful and efficient CNN architecture that has made significant contributions to the field of
computer vision. Its compound scaling method and efficient building blocks make it a popular choice for various image
analysis tasks, especially in scenarios where computational resources are limited.
%%time
import tensorflow as tf
from tensorflow.keras.applications import EfficientNetB0
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout
from tensorflow.keras import regularizers
# Create a MirroredStrategy
strategy = tf.distribute.MirroredStrategy(devices=['/gpu:0', '/gpu:1'])
# Load the pre-trained EfficientNetB0 model without the top classification layer
base_model_EfficientNet = EfficientNetB0(weights='imagenet', include_top=False, input_shape=(image_height, image_
# Add a global average pooling layer and output layer for classification
model_EfficientNet.add(GlobalAveragePooling2D())
model_EfficientNet.add(Dense(128, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_EfficientNet.add(Dropout(0.4))
model_EfficientNet.add(Dense(64, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_EfficientNet.add(Dropout(0.2))
model_EfficientNet.add(Dense(4, activation='softmax'))
# Model summary
print("Model Summary (EfficientNetB0):")
model_EfficientNet.summary()
print()
├─────────────────────────────────┼────────────────────────┼───────────────┤
│ dense_16 (Dense) │ ? │ 0 (unbuilt) │
├─────────────────────────────────┼────────────────────────┼───────────────┤
│ dropout_11 (Dropout) │ ? │ 0 (unbuilt) │
├─────────────────────────────────┼────────────────────────┼───────────────┤
│ dense_17 (Dense) │ ? │ 0 (unbuilt) │
└─────────────────────────────────┴────────────────────────┴───────────────┘
Total params: 4,049,571 (15.45 MB)
Trainable params: 0 (0.00 B)
Non-trainable params: 4,049,571 (15.45 MB)
Epoch 1/2
2024-08-24 19:36:54.302463: E tensorflow/core/grappler/optimizers/meta_optimizer.cc:961] layout failed: INVALID
_ARGUMENT: Size of values 0 does not match size of permutation 4 @ fanin shape inStatefulPartitionedCall/cond/e
lse/_742/cond/StatefulPartitionedCall/sequential_5_1/efficientnetb0_1/block2b_drop_1/stateless_dropout/SelectV2
-2-TransposeNHWCToNCHW-LayoutOptimizer
60/60 ━━━━━━━━━━━━━━━━━━━━ 98s 1s/step - accuracy: 0.2314 - loss: 1.6641 - val_accuracy: 0.2183 - val_loss: 1.5
422
Epoch 2/2
60/60 ━━━━━━━━━━━━━━━━━━━━ 65s 959ms/step - accuracy: 0.2513 - loss: 1.5095 - val_accuracy: 0.2284 - val_loss:
1.4732
Epoch 2: early stopping
Restoring model weights from the end of the best epoch: 1.
9/9 ━━━━━━━━━━━━━━━━━━━━ 2s 193ms/step - accuracy: 0.1881 - loss: 1.5437
Validation Loss: 1.5347
Validation Accuracy: 0.1878
CPU times: user 2min 52s, sys: 10.5 s, total: 3min 3s
Wall time: 2min 51s
NASNet
NASNet is a convolutional neural network (CNN) architecture that was designed using neural architecture search (NAS)
techniques. This means that the network's architecture was not manually designed by humans but rather was automatically
generated by a machine learning algorithm.
Neural Architecture Search: NASNet was generated using a reinforcement learning algorithm that searched through a vast space
of possible architectures to find the best one.
Inception-like Modules: NASNet is based on Inception-like modules, which are a combination of different convolutional filters with
different sizes.
Transfer Learning: NASNet can be used for transfer learning, where a pre-trained model is fine-tuned on a smaller dataset to solve
a related task.
Benefits of NASNet:
High Accuracy: NASNet has achieved state-of-the-art performance on various image classification benchmarks.
Efficient Architecture: The architecture of NASNet is designed to be computationally efficient.
Automation: The use of neural architecture search eliminates the need for manual design, making it easier to explore a wider range
of architectures.
Applications of NASNet:
Image Classification: NASNet is widely used for image classification tasks, such as object recognition, scene classification, and
fine-grained categorization.
Object Detection: NASNet has been incorporated into object detection architectures like Faster R-CNN and SSD.
Semantic Segmentation: NASNet has been applied to semantic segmentation tasks, where the goal is to assign a semantic label to
each pixel in an image.
In conclusion, NASNet is a powerful and efficient CNN architecture that has made significant contributions to the field of
computer vision. Its use of neural architecture search allows for the automatic generation of high-performing models, making it
a valuable tool for researchers and practitioners.
%%time
import tensorflow as tf
from tensorflow.keras.applications import NASNetMobile
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout
from tensorflow.keras import regularizers
# Add a global average pooling layer and output layer for classification
model_NASNet.add(GlobalAveragePooling2D())
model_NASNet.add(Dense(128, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_NASNet.add(Dropout(0.4))
model_NASNet.add(Dense(64, activation='relu', kernel_regularizer=regularizers.l2(0.001)))
model_NASNet.add(Dropout(0.2))
model_NASNet.add(Dense(4, activation='softmax'))
# Model summary
print("Model Summary (NASNetMobile):")
model_NASNet.summary()
print()
# Compile the model
model_NASNet.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
# Train the model with EarlyStopping (replace with your training logic)
history_NASNet = model_NASNet.fit(train_data, epochs=EPOCHS, validation_data=test_generator, callbacks=[early_stopp
plt.figure(figsize=[15, 5])
plt.show()
Prediction Result Samples
test_generator.reset()
img, label = next(test_generator)
prediction = model_Inception.predict(img)
test_pred_classes = np.argmax(prediction, axis=1)
plt.figure(figsize=[20, 20])
for i in range(20):
plt.subplot(5, 4, i+1)
plt.imshow(img[i])
plt.axis('off')
plt.title("Label : {}\n Prediction : {} {:.1f}%".format(class_names[np.argmax(label[i])], class_names[test_pred_c
plt.show()
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js