Your Name Comes Here commited on
Commit
d855114
β€’
1 Parent(s): fe27b40

first commit

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ 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
+ convnet_from_scratch_with_augmentation.keras filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
  title: Image Classification
3
- emoji: πŸ“Š
4
- colorFrom: blue
5
- colorTo: green
6
  sdk: gradio
7
- sdk_version: 3.42.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
1
  ---
2
  title: Image Classification
3
+ emoji: πŸ‘€
4
+ colorFrom: yellow
5
+ colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 3.41.2
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import os
10
+ import gradio as gr
11
+ from PIL import Image
12
+ from timeit import default_timer as timer
13
+ from tensorflow import keras
14
+ import numpy as np
15
+
16
+ MODEL = keras.models.load_model("convnet_from_scratch_with_augmentation.keras")
17
+
18
+ def predict(img):
19
+
20
+ # Start the timer
21
+ start_time = timer()
22
+
23
+ # Reading the image and size transformation
24
+ features = Image.open(img)
25
+ features = features.resize((180, 180))
26
+ features = np.array(features).reshape(1, 180,180,3)
27
+
28
+ # Create a prediction label and prediction probability dictionary for each prediction class
29
+ # This is the required format for Gradio's output parameter
30
+ pred_labels_and_probs = {'dog':float(MODEL.predict(features))} if MODEL.predict(features)> 0.5 else {'cat':100-float(MODEL.predict(features))}
31
+
32
+ # Calculate the prediction time
33
+ pred_time = round(timer() - start_time, 5)
34
+
35
+ # Return the prediction dictionary and prediction time
36
+ return pred_labels_and_probs, pred_time
37
+
38
+ # Create title, description and article strings
39
+ example_list = [["examples/" + example] for example in os.listdir("examples")]
40
+ title = "Classification Demo"
41
+ description = "Cat/Dog classification Tensorflow model with Augmented small dataset"
42
+
43
+ # Create the Gradio demo
44
+ demo = gr.Interface(fn=predict, # mapping function from input to output
45
+ inputs=gr.Image(type='filepath'), # what are the inputs?
46
+ outputs=[gr.Label(label="Predictions"), # what are the outputs?
47
+ gr.Number(label="Prediction time (s)")], # our fn has two outputs, therefore we have two outputs
48
+ examples=example_list,
49
+ title=title,
50
+ description=description,)
51
+
52
+ # Launch the demo!
53
+ demo.launch()
54
+
convnet_from_scratch_with_augmentation.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1646b4c5ba760dfb7f265dbfdaf7d37ef8743c6a44a5a77fe43aa22cd398434b
3
+ size 7982872
examples/cat.1502.jpg ADDED
examples/cat.1515.jpg ADDED
examples/dog.1508.jpg ADDED
examples/dog.1557.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ tensorflow==2.12.0
2
+ numpy==1.23.5
3
+ gradio==3.1.4