Challenge

Project 6 Mini Project

# MobileNet Architecture
#importing the needed libraries

import numpy as np
import cv2
import shutil
import random
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.layers import Dense, Activation
from tensorflow.keras.metrics import categorical_crossentropy
from tensorflow.keras.preprocessing import image
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.models import Model
import itertools
from tensorflow.keras.applications import imagenet_utils
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt


def read_image(an_image):
    """This function reads any image from a given path"""
    image = cv2.imread(an_image)
    return image

def mobilenet_arch():
    mobile_net = 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",
    )
    
    return mobile_net

def display_image(window_name, image_read):
    """This function any any image from a given path"""
    cv2.imshow(window_name, image_read)
    cv2.waitKey(0)
    
def prepare_image(a_dataset):
    img = image.load_img(a_dataset, 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)



read_image = read_image(an_image="samoyed.jpg")
display_image (window_name="Image", image_read=read_image)

mobilenet = mobilenet_arch()

preprocessed_image = prepare_image(a_dataset='samoyed.jpg')
algo_predictions = mobilenet.predict(preprocessed_image)

outcome = imagenet_utils.decode_predictions(algo_predictions)
print(outcome)
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.