fischori commited on
Commit
cd9ab2f
·
verified ·
1 Parent(s): 6dba2e7

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +56 -0
  3. requirements.txt +1 -0
  4. transferlearning_tools.keras +3 -0
.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
+ transferlearning_tools.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ model_path = "transferlearning_tools.keras"
7
+ model = tf.keras.models.load_model(model_path)
8
+
9
+ # Define the core prediction function
10
+ def predict_tools(image):
11
+ # Preprocess image
12
+ print(type(image))
13
+ image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
14
+ image = image.resize((150, 150)) # Resize the image to 150x150
15
+ image = np.array(image)
16
+ image = np.expand_dims(image, axis=0) # Expand dimensions to match the model input shape
17
+
18
+ # Predict
19
+ prediction = model.predict(image)
20
+
21
+ # Print the shape of the prediction to debug
22
+ print(f"Prediction shape: {prediction.shape}")
23
+
24
+ # Assuming the output is already softmax probabilities
25
+ probabilities = prediction[0]
26
+
27
+ # Print the probabilities array to debug
28
+ print(f"Probabilities: {probabilities}")
29
+
30
+ # Assuming your model was trained with these class names
31
+ class_names = ['Gasoline can', 'Hammer', 'Rope', 'Screw driver', 'Wrench']
32
+
33
+ # Create a dictionary of class probabilities
34
+ result = {class_names[i]: float(probabilities[i]) for i in range(len(class_names))}
35
+
36
+ return result
37
+
38
+
39
+ # Create the Gradio interface
40
+ input_image = gr.Image()
41
+ iface = gr.Interface(
42
+ fn=predict_tools,
43
+ inputs=input_image,
44
+ outputs=gr.Label(),
45
+ examples=["tools_examples/Gasoline can 1.jpg",
46
+ "tools_examples/Gasoline can 2.jpg",
47
+ "tools_examples/Hammer 1.jpg",
48
+ "tools_examples/Hammer 2.jpg",
49
+ "tools_examples/Rope 1.jpg",
50
+ "tools_examples/Rope 2.jpg",
51
+ "tools_examples/Screw driver 1.jpg",
52
+ "tools_examples/Screw driver 2.jpg",
53
+ "tools_examples/Wrench 1.jpg",
54
+ "tools_examples/Wrench 2.jpg"],
55
+ description="A simple mlp classification model for image classification using the mnist dataset.")
56
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ tensorflow
transferlearning_tools.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:302827d25c9e7f8a07f4c1a40af2c4f939a72291f3794b60b726b6b73d8bb09b
3
+ size 250609445