0% found this document useful (0 votes)
2 views2 pages

DL Exp3 Manasi - Ipynb - Colab

The document outlines a practical exercise in deep learning conducted by Manasi Sadashiv Choudhari, focusing on using pretrained neural networks (VGG16, ResNet50, and MobileNet) for image classification. It details the process of loading, preprocessing an image, and making predictions using these models on a specific image of a cat. The results show high probabilities for the class 'Persian_cat' across all models.

Uploaded by

samadhankanade29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

DL Exp3 Manasi - Ipynb - Colab

The document outlines a practical exercise in deep learning conducted by Manasi Sadashiv Choudhari, focusing on using pretrained neural networks (VGG16, ResNet50, and MobileNet) for image classification. It details the process of loading, preprocessing an image, and making predictions using these models on a specific image of a cat. The results show high probabilities for the class 'Persian_cat' across all models.

Uploaded by

samadhankanade29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

3/18/25, 10:01 AM DL exp3 Manasi.

ipynb - Colab

DEEP LEARNING Practical 3, Name : Manasi Sadashiv Choudhari, Roll no. : 57

Aim : Feeding the data to a pretrained neural network and making the predictions.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.preprocessing import image

VGG16

from tensorflow.keras.applications import VGG16


from tensorflow.keras.applications.vgg16 import preprocess_input, decode_predictions

# Load the VGG16 model with ImageNet weights


model = VGG16(weights='imagenet', include_top=True)

# Load and preprocess an image


img_path = '/content/cat3.jpg'
img = image.load_img(img_path, target_size=(224, 224))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array)

# Predict the class


predictions = model.predict(img_array)
# Decode predictions to readable labels
from tensorflow.keras.applications.vgg16 import decode_predictions
decoded_predictions = decode_predictions(predictions, top=5)[0]
for label, description, probability in decoded_predictions:
print(f"{description}: {probability:.4f}")

1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 816ms/step


Persian_cat: 0.9731
lynx: 0.0104
Angora: 0.0076
hamper: 0.0014
plastic_bag: 0.0008

ResNet50

from tensorflow.keras.applications import ResNet50


from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions

# Load the ResNet50 model with ImageNet weights


model = ResNet50(weights='imagenet', include_top=True)

# Load and preprocess an image


img_path = '/content/cat3.jpg'
img = image.load_img(img_path, target_size=(224, 224))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array)

# Predict the class


predictions = model.predict(img_array)
# Decode predictions to readable labels
decoded_predictions = decode_predictions(predictions, top=5)[0]
for label, description, probability in decoded_predictions:
print(f"{description}: {probability:.4f}")

1/1 ━━━━━━━━━━━━━━━━━━━━ 2s 2s/step


Persian_cat: 0.9918
Angora: 0.0029
lynx: 0.0015
Arctic_fox: 0.0005
tub: 0.0003

MobileNet

https://colab.research.google.com/drive/1J0oyKUke6CMZYdSihmikxTXYqiM6ka_y#scrollTo=OwnGJhqGWYKU&printMode=true 1/2
3/18/25, 10:01 AM DL exp3 Manasi.ipynb - Colab
from tensorflow.keras.applications import MobileNet
from tensorflow.keras.applications.mobilenet import preprocess_input, decode_predictions

# Load the MobileNet model with ImageNet weights


model = MobileNet(weights='imagenet', include_top=True)

# Load and preprocess an image


img_path = '/content/cat3.jpg'
img = image.load_img(img_path, target_size=(224, 224))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array)

# Predict the class


predictions = model.predict(img_array)
# Decode predictions to readable labels
decoded_predictions = decode_predictions(predictions, top=5)[0]
for label, description, probability in decoded_predictions:
print(f"{description}: {probability:.4f}")

1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 1s/step


Persian_cat: 0.9919
lynx: 0.0013
Japanese_spaniel: 0.0011
Angora: 0.0006
washbasin: 0.0005

https://colab.research.google.com/drive/1J0oyKUke6CMZYdSihmikxTXYqiM6ka_y#scrollTo=OwnGJhqGWYKU&printMode=true 2/2

You might also like