File size: 1,460 Bytes
dcd1223 |
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 |
#!/usr/bin/env python
# coding: utf-8
# In[82]:
import numpy as np
import tensorflow_datasets as tfds
import tensorflow as tf
import tensorflow_hub as hub
import sklearn
import random
from glob import glob
import matplotlib.pyplot as plt
import requests
# In[83]:
print("TF version:", tf.__version__)
print("Hub version:", hub.__version__)
print("GPU is", "available" if tf.config.list_physical_devices('GPU') else "NOT AVAILABLE")
# In[94]:
inception_net = tf.keras.applications.EfficientNetB7()
# In[100]:
import requests
response = requests.get("https://git.io/JJkYN")
labels = response.text.split("\n")
def classify_image(inp):
inp = inp.reshape((-1, 600, 600, 3))
inp = tf.keras.applications.efficientnet_v2.preprocess_input(inp)
prediction = inception_net.predict(inp).flatten()
confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
return confidences
# In[107]:
import gradio as gr
title = "Classifier"
Description = "Model,used :- Efficient Net B7,fine tuned on dataset 'https://www.kaggle.com/datasets/iamsouravbanerjee/animal-image-dataset-90-different-animals'"
gr.Interface(fn=classify_image,
title = title,
description = Description,
inputs=gr.Image(shape=(600, 600)),
outputs=gr.Label(num_top_classes=3),
examples=["data/animals/animals/antelope/0a37838e99.jpg", "data/animals/animals/starfish/0a63e965c2.jpg"]).launch(share=True)
|