File size: 828 Bytes
e22b55b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cv2
import numpy as np
import os

class Loader:
    def __init__(self,preprocessors=None):
        self.preprocessors=preprocessors
        if self.preprocessors is None:
            self.preprocessors=[]

    def load(self,imgpaths,verbose=-1):
        data=[]
        labels=[]

        for (i,imgpath) in enumerate(imgpaths):
            image=cv2.imread(imgpath)
            label= imgpath.split(os.path.sep)[-2]

            if self.preprocessors is not None:
                for p in self.preprocessors:
                    image=p.preprocess(image)

            data.append(image)
            labels.append(label)

            if verbose > 0 and i >0 and (i+1)% verbose==0:
                print("processed:{}/{}".format(i+1,len(imgpaths)))

        print("Done!")
        return (np.array(data),np.array(labels))