Study Pretrained Deep Neural Network Models for Images
Aim
To study the usage of pretrained deep neural network models for image classification, demonstrating feature extraction and prediction using transfer learning in Python (with Keras and TensorFlow).
Algorithm
-
Load a Pretrained Model (e.g., VGG16) with pre-learned weights on ImageNet.
-
Prepare Input Image: Load and resize the image to match the network input size, apply required preprocessing.
-
Predict: Pass the image through the pretrained model to obtain predictions.
-
Interpret Results: Decode the model’s output to obtain human-readable class labels.
Program
open cmd or terminal and then type "pip install tensorflow" to install the required packages
from tensorflow.keras.applications import VGG16 from tensorflow.keras.preprocessing import image from tensorflow.keras.applications.vgg16 import preprocess_input, decode_predictions import numpy as np # 1. Load pretrained VGG16 model model = VGG16(weights='imagenet') # 2. Load and preprocess sample image img_path = 'elephant.jpg' # Replace with your image img = image.load_img(img_path, target_size=(224, 224)) x = image.img_to_array(img) x = np.expand_dims(x, axis=0) x = preprocess_input(x) # 3. Predict using the model preds = model.predict(x) # 4. Output top 3 predictions print('Predicted:', decode_predictions(preds, top=3)[0])
Output (Sample: Elephant Image)
Result
-
The pretrained model can classify images with high accuracy, revealing top likely objects detected.
-
This exercise shows how transfer learning enables leveraging large-scale image features for new tasks without retraining networks from scratch.
-
The same approach supports feature extraction: intermediate model outputs can be used for clustering, retrieval, or further fine-tuning.

Join the conversation