Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- .gitattributes +1 -0
- app.py +74 -0
- recycling-model_transferlearning.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 |
+
recycling-model_transferlearning.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
model_path = "recycling-model_transferlearning.keras"
|
6 |
+
model = tf.keras.models.load_model(model_path)
|
7 |
+
# Define the core prediction function
|
8 |
+
def predict_recycling(image):
|
9 |
+
# Preprocess image
|
10 |
+
print(type(image))
|
11 |
+
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
12 |
+
image = image.resize((150, 150)) # Resize the image to 150x150
|
13 |
+
image = np.array(image)
|
14 |
+
image = np.expand_dims(image, axis=0) # Expand dimensions to create batch size of 1
|
15 |
+
|
16 |
+
# Predict
|
17 |
+
prediction = model.predict(image)
|
18 |
+
|
19 |
+
# Assuming the model's output layer uses softmax activation and there are three outputs
|
20 |
+
prediction = prediction.flatten()
|
21 |
+
predictions = np.round(prediction, 2) # Flatten the predictions and round them
|
22 |
+
|
23 |
+
# Separate the probabilities for each class
|
24 |
+
p_battery = predictions[0] # Probability for battery
|
25 |
+
p_biological = predictions[1] # Probability for biological
|
26 |
+
p_brownglass = predictions[2] # Probability for brown-glass
|
27 |
+
p_cardboard = predictions[3] # Probability for cardboard
|
28 |
+
p_clothes = predictions[4] # Probability for clothes
|
29 |
+
p_greenglass = predictions[5] # Probability for green-glass
|
30 |
+
p_metal = predictions[6] # Probability for metal
|
31 |
+
p_paper = predictions[7] # Probability for paper
|
32 |
+
p_plastic = predictions[8] # Probability for plastic
|
33 |
+
p_shoes = predictions[9] # Probability for shoes
|
34 |
+
p_whiteglass = predictions[10] # Probability for white-glass
|
35 |
+
|
36 |
+
return {
|
37 |
+
'battery': p_battery,
|
38 |
+
'biological': p_biological,
|
39 |
+
'brown-glass': p_brownglass,
|
40 |
+
'cardboard': p_cardboard,
|
41 |
+
'clothes': p_clothes,
|
42 |
+
'green-glass': p_greenglass,
|
43 |
+
'metal': p_metal,
|
44 |
+
'paper': p_paper,
|
45 |
+
'plastic': p_plastic,
|
46 |
+
'shoes': p_shoes,
|
47 |
+
'white-glass': p_whiteglass
|
48 |
+
}
|
49 |
+
# Create the Gradio interface
|
50 |
+
input_image = gr.Image()
|
51 |
+
interface = gr.Interface(
|
52 |
+
fn=predict_recycling,
|
53 |
+
inputs=input_image,
|
54 |
+
outputs=gr.Label(),
|
55 |
+
examples=["test/battery1.jpg", "test/battery2.jpg", "test/battery3.jpg",
|
56 |
+
"test/biological1.jpg", "test/biological2.jpg", "test/biological3.jpg",
|
57 |
+
"test/brown-glass1.jpg", "test/brown-glass2.jpg", "test/brown-glass3.jpg",
|
58 |
+
"test/cardboard1.jpg", "test/cardboard2.jpg", "test/cardboard3.jpg",
|
59 |
+
"test/clothes1.jpg", "test/clothes2.jpg", "test/clothes3.jpg",
|
60 |
+
"test/green-glass1.jpg", "test/green-glass2.jpg", "test/green-glass3.jpg",
|
61 |
+
"test/metal1.jpg", "test/metal2.jpg", "test/metal3.jpg",
|
62 |
+
"test/paper1.jpg", "test/paper2.jpg", "test/paper3.jpg",
|
63 |
+
"test/plastic1.jpg", "test/plastic2.jpg", "test/plastic3.jpg",
|
64 |
+
"test/shoes1.jpg", "test/shoes2.jpg", "test/shoes3.jpg",
|
65 |
+
"test/white-glass1.jpg", "test/white-glass2.jpg", "test/white-glass3.jpg"],
|
66 |
+
title="Bildklassifikation für Recycling-Materialien",
|
67 |
+
description="Dieses Tool klassifiziert Bilder in verschiedene Recycling-Kategorien. Bitte lade ein Bild hoch, benutze die Kamera oder verwende ein Beispiel von unten, um die Klassifikation zu sehen.",
|
68 |
+
theme = gr.themes.Soft(
|
69 |
+
primary_hue="emerald",
|
70 |
+
secondary_hue="emerald",
|
71 |
+
).set(
|
72 |
+
background_fill_primary='*neutral_100'
|
73 |
+
))
|
74 |
+
interface.launch()
|
recycling-model_transferlearning.keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1e4efe3562b9b1c36eccc8b31e0ca5ecfcbe2e149687d1e733a4f5da622fb83c
|
3 |
+
size 250756852
|