forked from nttuan8/DeepLearningForComputerVisionWithPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleDatasetLoader.py
More file actions
33 lines (27 loc) · 941 Bytes
/
SimpleDatasetLoader.py
File metadata and controls
33 lines (27 loc) · 941 Bytes
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
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 19 09:08:58 2018
@author: DELL
"""
import numpy as np
import cv2
import os
class SimpleDatasetLoader:
def __init__(self, processors=None):
self.processors = processors
if self.processors is None:
self.processors = []
def load(self, imagePaths, verbose=-1):
data = []
labels = []
for (i, imagePath) in enumerate(imagePaths):
image = cv2.imread(imagePath)
label = imagePath.split(os.path.sep)[-2]
if self.processors is not None:
for p in self.processors:
image = p.preprocess(image)
data.append(image)
labels.append(label)
if verbose > 0 and i > 0 and (i+1)%verbose==0:
print("Info process {}/{}".format(i+1, len(imagePaths)))
return np.array(data), np.array(labels)