Challenge

Project 6 Mini Project

#IMPORT ALL THE NECESSARY MODULE LIBARARIES SUCH AS TENSORFLOW AND ITS BASIC LAYERS

import numpy as np
import cv2
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.layers import Dense, Activation
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.metrics import categorical_crossentropy
from tensorflow.keras.preprocessing import image
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.applications import imagenet_utils
from sklearn.metrics import confusion_matrix
from tensorflow.keras.models import Model
import itertools
import shutil
import random
import matplotlib.pyplot as plt
 
# USE THE MOBILENET MODEL TO CHECK THE QUALITY OF CLASSIFICATION OF THIS PERTICULAR MODULE ON THE BASIS OF THE ACCORDANCE OF IMAGENET CLASSES.
mobile = tf.keras.applications.mobilenet.MobileNet(  input_shape=(224, 224, 3),
    alpha=1.0,
    include_top=True,
    weights="imagenet",
    input_tensor=None,
    classes=1000,
    pooling=None,
    classifier_activation="softmax",
    )
Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/mobilenet/mobilenet_1_0_224_tf.h5
17225924/17225924 [==============================] - 2s 0us/step
 
def prepare_image(file):
    img = image.load_img(file, target_size=(224, 224))
    img_array = image.img_to_array(img)
    img_array_expanded_dims = np.expand_dims(img_array, axis=0)
    return tf.keras.applications.mobilenet.preprocess_input(img_array_expanded_dims)
img_read = cv2.imread('tiger.jpg')
cv2.imshow('img', img_read)
cv2.waitKey(0)


FIG.1:- INPUT IMAGE
 
preprocessed_image = prepare_image('tiger.jpg')
predictions = mobile.predict(preprocessed_image)
 
results = imagenet_utils.decode_predictions(predictions)
print(results)
FIG.2:- RESULTS OUTPUT IMAGE
EXPLANATION FOR OUTPUT:-
1. THE INPUTED IMAGE CONTAINS A TIGER IN SITTING POSITION.
2. THE RESPECTIVE INTERFACE OF IMAGENET DATASET PROFOUNDLY PREDICTS THAT THE IMAGE HAS A TIGER IN IT, IN APPROX 66MSEC OF TIME.
3. SO THIS IMPLIES THAT THE CURRENT WORKING MODULE OF IMAGENET IS DOING A PERFECT PREDICTION TO CLASSIFIES ITS INPUT DATAS.
 
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.