VikramxD commited on
Commit
dcd1223
1 Parent(s): e792ed4

Upload model.py

Browse files
Files changed (1) hide show
  1. model.py +63 -0
model.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[82]:
5
+
6
+
7
+ import numpy as np
8
+ import tensorflow_datasets as tfds
9
+ import tensorflow as tf
10
+ import tensorflow_hub as hub
11
+ import sklearn
12
+ import random
13
+ from glob import glob
14
+ import matplotlib.pyplot as plt
15
+ import requests
16
+
17
+
18
+ # In[83]:
19
+
20
+
21
+ print("TF version:", tf.__version__)
22
+ print("Hub version:", hub.__version__)
23
+ print("GPU is", "available" if tf.config.list_physical_devices('GPU') else "NOT AVAILABLE")
24
+
25
+
26
+ # In[94]:
27
+
28
+
29
+
30
+ inception_net = tf.keras.applications.EfficientNetB7()
31
+
32
+
33
+ # In[100]:
34
+
35
+
36
+ import requests
37
+
38
+ response = requests.get("https://git.io/JJkYN")
39
+ labels = response.text.split("\n")
40
+
41
+ def classify_image(inp):
42
+ inp = inp.reshape((-1, 600, 600, 3))
43
+ inp = tf.keras.applications.efficientnet_v2.preprocess_input(inp)
44
+ prediction = inception_net.predict(inp).flatten()
45
+ confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
46
+ return confidences
47
+
48
+
49
+ # In[107]:
50
+
51
+
52
+ import gradio as gr
53
+ title = "Classifier"
54
+ Description = "Model,used :- Efficient Net B7,fine tuned on dataset 'https://www.kaggle.com/datasets/iamsouravbanerjee/animal-image-dataset-90-different-animals'"
55
+
56
+ gr.Interface(fn=classify_image,
57
+ title = title,
58
+ description = Description,
59
+
60
+ inputs=gr.Image(shape=(600, 600)),
61
+ outputs=gr.Label(num_top_classes=3),
62
+ examples=["data/animals/animals/antelope/0a37838e99.jpg", "data/animals/animals/starfish/0a63e965c2.jpg"]).launch(share=True)
63
+