-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (39 loc) · 1.58 KB
/
main.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
# -*- coding: utf-8 -*-
from util import get_class_files_tuple
from model import load_model
from image import load_image, preprocess_image
import numpy as np
def main():
# 1. Carrega o modelo
model_path = './models/glomeruloesclerose'
model = load_model(model_path)
# 2. Pasta contendo os arquivos de imagem
dataset_folder = './dataset/'
dataset_tuple = get_class_files_tuple(dataset_folder)
# Iterando sobre o dicionário
for class_name, files_names in dataset_tuple:
print('-------Processing class: ', class_name, ' -------')
for image_name in files_names:
image_path = dataset_folder+class_name+'/'+image_name
classes = {
'com': 0,
'sem': 1,
}
# Load image
image = load_image(image_path)
height, width, _ = image.shape
# Preprocess Image
# Get model's input shape
_, input_width, input_height, _ = model.layers[0].input_shape
preprocessed_image = preprocess_image(
image, (input_width, input_height))
# Predict Image class
predictions = model.predict(preprocessed_image)
predicted_class = np.argmax(predictions)
if predicted_class == 0 and predictions[0][predicted_class] != 1.0:
print('Image name: ' + image_path)
print("Prediction: with(" +
str(predictions[0][0]) + ') without(' + str(predictions[0][1])+')')
print(' *** Done ***\n')
if __name__ == '__main__':
main()