-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPredictor_Interfaz_Consola.py
156 lines (105 loc) · 4.01 KB
/
Predictor_Interfaz_Consola.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python
# coding: utf-8
# In[79]:
import numpy as np
from keras.preprocessing.image import load_img, img_to_array
from keras.models import load_model
# In[80]:
from os import system
# In[81]:
longitud, altura = 224, 224
modelo_mobilenet = 'E:/Documentos/UTP/Cuarto_Anio/Sistemas_basados_en_el_conocimiento/Proyecto/ModeloMobileNetV2/modelo_proyecto_MobileNetV2.h5'
pesos_mobilenet = 'E:/Documentos/UTP/Cuarto_Anio/Sistemas_basados_en_el_conocimiento/Proyecto/ModeloMobileNetV2/pesos__proyecto_MobileNetV2.h5'
modelo_vgg16 = 'E:/Documentos/UTP/Cuarto_Anio/Sistemas_basados_en_el_conocimiento/Proyecto/ModeloVGG16/modelo_vgg16.h5'
pesos_vgg16 = 'E:/Documentos/UTP/Cuarto_Anio/Sistemas_basados_en_el_conocimiento/Proyecto/ModeloVGG16/pesos_modelo_vgg16.h5'
#cnn = load_model(modelo)
#cnn.load_weights(pesos)
# In[82]:
def mobilenet():
system("cls")
print("___________________________________________")
print("Ha seleccionado la arquitectura MobileNetV2")
print("___________________________________________")
print("Ingrese el nombre de una imagen contenida en la carpeta: ")
print("E:/Documentos/UTP/Cuarto_Anio/Sistemas_basados_en_el_conocimiento/Proyecto/DataSet/imagenes_prueba/prueba")
imagen = input("Nombre: ")
imagen_predecir = "E:/Documentos/UTP/Cuarto_Anio/Sistemas_basados_en_el_conocimiento/Proyecto/DataSet/imagenes_prueba/prueba/"+imagen
#print(imagen_predecir)
predictor_mobilenet(imagen_predecir)
# In[83]:
def vgg16():
system("cls")
print("_____________________________________")
print("Ha seleccionado la arquitectura VGG16")
print("_____________________________________")
print("Ingrese el nombre de una imagen contenida en la carpeta: ")
print("E:/Documentos/UTP/Cuarto_Anio/Sistemas_basados_en_el_conocimiento/Proyecto/DataSet/imagenes_prueba/prueba")
imagen = input("Nombre: ")
imagen_predecir = "E:/Documentos/UTP/Cuarto_Anio/Sistemas_basados_en_el_conocimiento/Proyecto/DataSet/imagenes_prueba/prueba/"+imagen
#print(imagen_predecir)
predictor_vgg16(imagen_predecir)
# In[84]:
def imprimir():
print("___________________________________")
print("Bienvenido al clasificador Covid-19")
print("___________________________________")
print()
print("Porfavor seleccione la red neuronal que desea utilizar para realizar su clasificación:")
print("1. MobileNetV2")
print("2. VGG16")
print("3. <--- Salir")
print()
# In[85]:
def menu():
#system("cls")
salir = False
opcion = 0
while not salir:
imprimir()
opcion = int(input("Opcion: "))
if opcion == 1:
#print ("Opcion 1")
mobilenet()
elif opcion == 2:
vgg16()
elif opcion == 3:
salir = True
else:
print ("Introduce un numero entre 1 y 3")
print ("Gracias por utilizar este clasificador!")
# In[86]:
def predictor_mobilenet(file):
cnn = load_model(modelo_mobilenet)
cnn.load_weights(pesos_mobilenet)
x = load_img(file, target_size = (longitud, altura))
x = img_to_array(x)
x = np.expand_dims(x, axis = 0)
arreglo = cnn.predict(x)
resultado = arreglo[0]
respuesta = np.argmax(resultado)
if respuesta == 0:
print ('Positivo para Covid!')
elif respuesta == 1:
print ('No es afección por Covid!')
return respuesta
# In[87]:
def predictor_vgg16(file):
cnn = load_model(modelo_vgg16)
cnn.load_weights(pesos_vgg16)
x = load_img(file, target_size = (longitud, altura))
x = img_to_array(x)
x = np.expand_dims(x, axis = 0)
arreglo = cnn.predict(x)
resultado = arreglo[0]
respuesta = np.argmax(resultado)
if respuesta == 0:
print ('Positivo para Covid!')
elif respuesta == 1:
print ('No es afección por Covid!')
return respuesta
# In[88]:
if __name__ == '__main__':
menu()
# In[14]:
#predictor('E:/Documentos/UTP/Cuarto_Anio/Sistemas_basados_en_el_conocimiento/Proyecto/imagenes_internet/ejemplonormal (4).jpg')
# In[ ]: