-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch.py
46 lines (33 loc) · 988 Bytes
/
batch.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
"""
Author: Sigve Rokenes
Date: February, 2019
Batch manager for pokemon generation
"""
import os, random
import skimage as sk
from skimage import io
from skimage import img_as_float
from skimage import transform
class PokeBatch:
def __init__(self, resize=None):
path = "data/processed/"
paths = os.listdir(path)
self.images = []
self.next = 0
for p in paths:
img = sk.io.imread(path+p)
if resize:
img = transform.resize(img, resize)
img = img_as_float(img)
self.images.append(img)
def shuffle(self):
random.shuffle(self.images)
def sample(self, size=1):
return random.sample(self.images, size)
def next_batch(self, batch_size):
batch = self.images[self.next:self.next+batch_size]
self.next += batch_size
self.next %= len(self.images)
return batch
def num_examples(self):
return len(self.images)