File size: 3,793 Bytes
69363a4
 
 
 
bca802a
e506320
69363a4
e506320
69363a4
b45775d
 
 
 
 
 
9871838
b45775d
 
69363a4
12aa0f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69363a4
 
 
 
0ac849e
bca802a
0ac849e
69363a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ac849e
 
 
 
69363a4
 
 
 
d659f8e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import gradio as gr
import requests
import tensorflow as tf
import tensorflow_hub as hub
import cv2
import tf_keras as keras

TF_USE_LEGACY_KERAS=1
path = '20220804-16551659632113-all-images-Adam.h5'
#aks----------------
# Register custom objects
custom_objects = {'KerasLayer': hub.KerasLayer}

# Load the model with custom objects registered
with tf.keras.utils.custom_object_scope(custom_objects):
    model = tf.keras.models.load_model(path)
#aks end-----------
# model = tf.keras.models.load_model((path),custom_objects={"KerasLayer":hub.KerasLayer})

labels = ['affenpinscher', 'afghan_hound', 'african_hunting_dog', 'airedale',
    'american_staffordshire_terrier', 'appenzeller',
    'australian_terrier', 'basenji', 'basset', 'beagle',
    'bedlington_terrier', 'bernese_mountain_dog',
    'black-and-tan_coonhound', 'blenheim_spaniel', 'bloodhound',
    'bluetick', 'border_collie', 'border_terrier', 'borzoi',
    'boston_bull', 'bouvier_des_flandres', 'boxer',
    'brabancon_griffon', 'briard', 'brittany_spaniel', 'bull_mastiff',
    'cairn', 'cardigan', 'chesapeake_bay_retriever', 'chihuahua',
    'chow', 'clumber', 'cocker_spaniel', 'collie',
    'curly-coated_retriever', 'dandie_dinmont', 'dhole', 'dingo',
    'doberman', 'english_foxhound', 'english_setter',
    'english_springer', 'entlebucher', 'eskimo_dog',
    'flat-coated_retriever', 'french_bulldog', 'german_shepherd',
    'german_short-haired_pointer', 'giant_schnauzer',
    'golden_retriever', 'gordon_setter', 'great_dane',
    'great_pyrenees', 'greater_swiss_mountain_dog', 'groenendael',
    'ibizan_hound', 'irish_setter', 'irish_terrier',
    'irish_water_spaniel', 'irish_wolfhound', 'italian_greyhound',
    'japanese_spaniel', 'keeshond', 'kelpie', 'kerry_blue_terrier',
    'komondor', 'kuvasz', 'labrador_retriever', 'lakeland_terrier',
    'leonberg', 'lhasa', 'malamute', 'malinois', 'maltese_dog',
    'mexican_hairless', 'miniature_pinscher', 'miniature_poodle',
    'miniature_schnauzer', 'newfoundland', 'norfolk_terrier',
    'norwegian_elkhound', 'norwich_terrier', 'old_english_sheepdog',
    'otterhound', 'papillon', 'pekinese', 'pembroke', 'pomeranian',
    'pug', 'redbone', 'rhodesian_ridgeback', 'rottweiler',
    'saint_bernard', 'saluki', 'samoyed', 'schipperke',
    'scotch_terrier', 'scottish_deerhound', 'sealyham_terrier',
    'shetland_sheepdog', 'shih-tzu', 'siberian_husky', 'silky_terrier',
    'soft-coated_wheaten_terrier', 'staffordshire_bullterrier',
    'standard_poodle', 'standard_schnauzer', 'sussex_spaniel',
    'tibetan_mastiff', 'tibetan_terrier', 'toy_poodle', 'toy_terrier',
    'vizsla', 'walker_hound', 'weimaraner', 'welsh_springer_spaniel',
    'west_highland_white_terrier', 'whippet',
    'wire-haired_fox_terrier', 'yorkshire_terrier']

# load the model
def predict_breed(image):

    ##---aks
    image = cv2.resize(image, (224, 224))
    ##aks end
    # reshape the input
    image = image.reshape((-1, 224, 224, 3))

    image = tf.image.convert_image_dtype(image, dtype=tf.float32)
    
    image = tf.constant(image)

    # prediction = model_1000_images.predict(image).flatten()
    prediction = model.predict(image).flatten()
    
    # return prediction labels
    return {labels[i]: float(prediction[i]) for i in range(120)}

title = "Dog Vision"
description = "A Dog Breed Classifier trained on the MobileNetV2 Deep Learning Model result."

examples = ['German.jpg']

enable_queue=True

gr.Interface(
   fn=predict_breed,
    inputs=gr.Image(),
    outputs=gr.Label(num_top_classes=3),
   # inputs=gr.inputs.Image(shape=(224, 224)),
   # outputs=gr.outputs.Label(num_top_classes=3),
   title=title,
   description=description,
   examples=examples,
   cache_examples=True,
   examples_per_page=2).launch(debug=True,enable_queue=enable_queue)