Commit
·
97ccc10
1
Parent(s):
7e00cfa
Subindo arquivos
Browse files- README.md +19 -1
- app.py +56 -0
- converted_keras.zip +3 -0
- example1.jpg +0 -0
- example2.jpg +0 -0
- requirements.txt +4 -0
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title: Gtm
|
3 |
emoji: 😻
|
4 |
colorFrom: green
|
5 |
colorTo: red
|
@@ -10,4 +10,22 @@ pinned: false
|
|
10 |
license: ecl-2.0
|
11 |
---
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Gtm-Keras-H5-Predictor
|
3 |
emoji: 😻
|
4 |
colorFrom: green
|
5 |
colorTo: red
|
|
|
10 |
license: ecl-2.0
|
11 |
---
|
12 |
|
13 |
+
## Description
|
14 |
+
In Google Teachable Machine, after training, under 'Export Model', go to 'Tensorflow', click on 'Keras' and then 'Download my model' (wait a moment). The zip will contain the Keras .h5 model. This application allows users to upload these models and test them with their own images.
|
15 |
+
|
16 |
+
## How to Use
|
17 |
+
1. Train a model in Google Teachable Machine.
|
18 |
+
2. Export and download the model as a Keras .h5 file (in Tensorflow, in middle, click on Keras, Download my model).
|
19 |
+
3. Upload the model (.zip or .h5) and your test images to the application.
|
20 |
+
4. View the predictions made by the model.
|
21 |
+
|
22 |
+
## Developer
|
23 |
+
Developed by Ramon Mayor Martins (2023)
|
24 |
+
|
25 |
+
- E-mail: [[email protected]](mailto:[email protected])
|
26 |
+
- Homepage: [https://rmayormartins.github.io/](https://rmayormartins.github.io/)
|
27 |
+
- Twitter: [@rmayormartins](https://twitter.com/rmayormartins)
|
28 |
+
- GitHub: [https://github.com/rmayormartins](https://github.com/rmayormartins)
|
29 |
+
|
30 |
+
|
31 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
import zipfile
|
6 |
+
import tempfile
|
7 |
+
import os
|
8 |
+
|
9 |
+
def classify_images(uploaded_file, images):
|
10 |
+
|
11 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
12 |
+
with zipfile.ZipFile(uploaded_file, 'r') as zip_ref:
|
13 |
+
zip_ref.extractall(temp_dir)
|
14 |
+
model_path = os.path.join(temp_dir, 'keras_model.h5')
|
15 |
+
labels_path = os.path.join(temp_dir, 'labels.txt')
|
16 |
+
|
17 |
+
|
18 |
+
loaded_model = load_model(model_path)
|
19 |
+
|
20 |
+
|
21 |
+
with open(labels_path, 'r') as file:
|
22 |
+
class_names = file.read().splitlines()
|
23 |
+
|
24 |
+
|
25 |
+
predictions = []
|
26 |
+
for img in images:
|
27 |
+
with Image.open(img) as pil_image:
|
28 |
+
image = pil_image.resize((224, 224))
|
29 |
+
image = np.array(image)
|
30 |
+
image = image / 255.0
|
31 |
+
image = np.expand_dims(image, axis=0)
|
32 |
+
|
33 |
+
prediction = loaded_model.predict(image)
|
34 |
+
predicted_class = class_names[np.argmax(prediction)]
|
35 |
+
predictions.append(predicted_class)
|
36 |
+
|
37 |
+
return predictions
|
38 |
+
|
39 |
+
iface = gr.Interface(
|
40 |
+
fn=classify_images,
|
41 |
+
inputs=[
|
42 |
+
gr.File(label="Upload do Modelo (.h5 or .zip (with .h5))"),
|
43 |
+
gr.Files(label="Upload of Images")
|
44 |
+
],
|
45 |
+
outputs="text",
|
46 |
+
title="GTM-Keras-h5-Predictor",
|
47 |
+
description="In Google Teachable Machine, after training, under 'Export Model', go to 'Tensorflow', click on 'Keras' and then 'Download my model' (wait a moment). The zip will contain the Keras .h5 model."
|
48 |
+
)
|
49 |
+
|
50 |
+
iface.add_example(inputs=["converted_keras.zip", ["example1.jpg", "example2.jpg"]])
|
51 |
+
|
52 |
+
|
53 |
+
if __name__ == "__main__":
|
54 |
+
iface.launch(debug=True)
|
55 |
+
|
56 |
+
|
converted_keras.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ac6edc498947ade81a3d42a6a4140f55c9e5e8baccba06429c1ba4c798132a0a
|
3 |
+
size 2453667
|
example1.jpg
ADDED
![]() |
example2.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
tensorflow
|
3 |
+
Pillow
|
4 |
+
numpy
|