Spaces:
Sleeping
Sleeping
app files added
Browse files- .gitattributes +2 -0
- app.py.py +70 -0
- convnet_from_scratch_with_augmentation.keras +3 -0
- examples/cat.1505.jpg +0 -0
- examples/cat.1515.jpg +0 -0
- examples/dog.1508.jpg +0 -0
- examples/dog.1557.jpg +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.psd filter=lfs diff=lfs merge=lfs -text
|
37 |
+
convnet_from_scratch_with_augmentation.keras filter=lfs diff=lfs merge=lfs -text
|
app.py.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""gradio_deploy.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/13X2E9v7GxryXyT39R5CzxrNwxfA6KMFJ
|
8 |
+
"""
|
9 |
+
|
10 |
+
!pip install gradio
|
11 |
+
|
12 |
+
import gradio as gr
|
13 |
+
from PIL import Image
|
14 |
+
from timeit import default_timer as timer
|
15 |
+
from tensorflow import keras
|
16 |
+
import numpy as np
|
17 |
+
|
18 |
+
MODEL = keras.models.load_model(
|
19 |
+
"convnet_from_scratch_with_augmentation.keras")
|
20 |
+
|
21 |
+
def predict(img):
|
22 |
+
|
23 |
+
# Start the timer
|
24 |
+
start_time = timer()
|
25 |
+
|
26 |
+
# Reading the image and size transformation
|
27 |
+
features = Image.open(img)
|
28 |
+
features = features.resize((180, 180))
|
29 |
+
features = np.array(features).reshape(1, 180,180,3)
|
30 |
+
|
31 |
+
# Create a prediction label and prediction probability dictionary for each prediction class
|
32 |
+
# This is the required format for Gradio's output parameter
|
33 |
+
pred_labels_and_probs = {'dog' if MODEL.predict(features)> 0.5 else 'cat':float(MODEL.predict(features))}
|
34 |
+
|
35 |
+
# Calculate the prediction time
|
36 |
+
pred_time = round(timer() - start_time, 5)
|
37 |
+
|
38 |
+
# Return the prediction dictionary and prediction time
|
39 |
+
return pred_labels_and_probs, pred_time
|
40 |
+
|
41 |
+
predict('/content/cat.1505.jpg')
|
42 |
+
|
43 |
+
# Create title, description and article strings
|
44 |
+
title = "Classification Demo"
|
45 |
+
description = "Cat/Dog classification Tensorflow model with Augmentted small dataset"
|
46 |
+
|
47 |
+
# Create the Gradio demo
|
48 |
+
demo = gr.Interface(fn=predict, # mapping function from input to output
|
49 |
+
inputs=gr.Image(type='filepath'), # what are the inputs?
|
50 |
+
outputs=[gr.Label(label="Predictions"), # what are the outputs?
|
51 |
+
gr.Number(label="Prediction time (s)")], # our fn has two outputs, therefore we have two outputs
|
52 |
+
title=title,
|
53 |
+
description=description,)
|
54 |
+
|
55 |
+
# Launch the demo!
|
56 |
+
demo.launch(debug=False, # print errors locally?
|
57 |
+
share=True) # generate a publically shareable URL?
|
58 |
+
|
59 |
+
pip install tensorflow
|
60 |
+
|
61 |
+
import PIL
|
62 |
+
|
63 |
+
import tensorflow as tf
|
64 |
+
|
65 |
+
import timeit
|
66 |
+
|
67 |
+
print(gr.__version__)
|
68 |
+
print(np.__version__)
|
69 |
+
print(tf.__version__)
|
70 |
+
print(PIL.__version__)
|
convnet_from_scratch_with_augmentation.keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d5c2baab54f3fa167009426c924158359eac870339e4c0876376523ec50b9f7a
|
3 |
+
size 7982872
|
examples/cat.1505.jpg
ADDED
examples/cat.1515.jpg
ADDED
examples/dog.1508.jpg
ADDED
examples/dog.1557.jpg
ADDED