-
Notifications
You must be signed in to change notification settings - Fork 0
/
Buscador.py
35 lines (31 loc) · 1.25 KB
/
Buscador.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
import os
import numpy as np
class Buscador():
def __init__(self,paths,numero_clases):
self.paths = paths
self.numero_clases = numero_clases
self.x_train = []
self.y_train = []
self.x_test = []
self.y_test = []
def encuentra_imagenes_y_labels(self):
for path in self.paths:
for root, dirs, files in os.walk(path):
for file_name in files:
if (file_name.endswith(".png")):
full_path = os.path.join(root,file_name)
self.obtiene_labels_desde_imagen(full_path)
def obtiene_labels_desde_imagen(self, full_path):
labels = np.zeros(self.numero_clases, dtype=np.float32)
if 'train' in full_path:
y_label_dir = os.path.dirname(os.path.dirname(full_path))
y_label = os.path.basename(y_label_dir)
labels[int(y_label)] = 1.0
self.y_train.append(list(labels))
self.x_train.append(full_path)
if 'test' in full_path:
y_label_dir = os.path.dirname(full_path)
y_label = os.path.basename(y_label_dir)
labels[int(y_label)] = 1.0
self.y_test.append(list(labels))
self.x_test.append(full_path)