Spaces:
Sleeping
Sleeping
Commit
·
587269e
1
Parent(s):
d045f7b
Atualização
Browse files
README.md
CHANGED
@@ -31,7 +31,11 @@ TensorFlow e MobileNetV2
|
|
31 |
|
32 |
## Mais informações
|
33 |
|
34 | |
|
|
|
|
|
|
|
|
35 |
|
36 |
## Para mim
|
37 |
1. Eu atualizo o modelo pelo image-classifier3 no Colab, salvo no Drive o modelo em MODEL, e carrego localmente na pasta Documents para o git
|
|
|
31 |
|
32 |
## Mais informações
|
33 |
|
34 |
+
Desenvolvido por Ramon Mayor Martins (2023)
|
35 |
+
mail [email protected]
|
36 |
+
hp https://rmayormartins.github.io/
|
37 |
+
twitter @rmayormartins
|
38 |
+
github https://github.com/rmayormartins
|
39 |
|
40 |
## Para mim
|
41 |
1. Eu atualizo o modelo pelo image-classifier3 no Colab, salvo no Drive o modelo em MODEL, e carrego localmente na pasta Documents para o git
|
app.py
CHANGED
@@ -3,27 +3,26 @@ import tensorflow as tf
|
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
5 |
|
6 |
-
|
7 |
-
# O modelo deve estar na mesma pasta que este script
|
8 |
model = tf.keras.models.load_model('meu_modelo.h5')
|
9 |
|
10 |
def predict_image(img):
|
11 |
-
|
12 |
img = np.array(img)
|
13 |
|
14 |
-
|
15 |
img = tf.image.resize(img, (224, 224))
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
img = img / 127.5 - 1
|
20 |
|
21 |
-
|
22 |
img = np.expand_dims(img, axis=0)
|
23 |
|
24 |
prediction = model.predict(img)
|
25 |
|
26 |
-
|
27 |
if prediction < 0.5:
|
28 |
result = {"ai": float(1 - prediction[0][0]), "human": float(prediction[0][0])}
|
29 |
else:
|
@@ -31,14 +30,13 @@ def predict_image(img):
|
|
31 |
|
32 |
return result
|
33 |
|
34 |
-
|
35 |
-
# As imagens de exemplo devem estar na mesma pasta que este script
|
36 |
exemplos = [
|
37 |
'vangoghai.jpg',
|
38 |
'vangoghhuman.jpg'
|
39 |
]
|
40 |
|
41 |
-
#
|
42 |
image_input = gr.Image()
|
43 |
label_output = gr.Label()
|
44 |
|
@@ -49,5 +47,6 @@ interface = gr.Interface(
|
|
49 |
examples=exemplos
|
50 |
)
|
51 |
|
52 |
-
|
53 |
-
interface.launch()
|
|
|
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
5 |
|
6 |
+
|
|
|
7 |
model = tf.keras.models.load_model('meu_modelo.h5')
|
8 |
|
9 |
def predict_image(img):
|
10 |
+
|
11 |
img = np.array(img)
|
12 |
|
13 |
+
|
14 |
img = tf.image.resize(img, (224, 224))
|
15 |
|
16 |
+
# MobileNetV2:
|
17 |
+
|
18 |
img = img / 127.5 - 1
|
19 |
|
20 |
+
|
21 |
img = np.expand_dims(img, axis=0)
|
22 |
|
23 |
prediction = model.predict(img)
|
24 |
|
25 |
+
|
26 |
if prediction < 0.5:
|
27 |
result = {"ai": float(1 - prediction[0][0]), "human": float(prediction[0][0])}
|
28 |
else:
|
|
|
30 |
|
31 |
return result
|
32 |
|
33 |
+
|
|
|
34 |
exemplos = [
|
35 |
'vangoghai.jpg',
|
36 |
'vangoghhuman.jpg'
|
37 |
]
|
38 |
|
39 |
+
#gradio
|
40 |
image_input = gr.Image()
|
41 |
label_output = gr.Label()
|
42 |
|
|
|
47 |
examples=exemplos
|
48 |
)
|
49 |
|
50 |
+
|
51 |
+
interface.launch(debug=True)
|
52 |
+
|