-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_trace.py
More file actions
59 lines (41 loc) · 1.46 KB
/
load_trace.py
File metadata and controls
59 lines (41 loc) · 1.46 KB
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
50
51
52
53
54
55
56
57
import numpy as np
import matplotlib as mpl
import trace_data_new
#mpl.use("Agg")
#import matplotlib.pyplot as plt
class TraceData(object):
"""An object of InputData must have images and labels.
Attributes:
images: A list of lists of image pixels.
labels: A list of one-hot label lists.
"""
def __init__(self, folder=".", images=[], labels=[]):
"""Return an InputData object."""
self.folder = folder
self.images = []
self.length = 0
def get_train(self, even=None):
"""Generate and get train images and labels."""
self.images, _, _, _, _ = trace_data_new.get_my_teacher()
self.length = len(self.images)
def get_test(self, even=None):
"""Generate and get train images and labels."""
self.get_train(even)
def get_length(self):
"""Return the number of images."""
return self.length
def next_batch(self, batch_size):
"""Returns a batch of size batch_size of data."""
all_idx = np.arange(0, self.length)
np.random.shuffle(all_idx)
batch_idx = all_idx[:batch_size]
batch_imgs = [self.images[i] for i in batch_idx]
return batch_imgs
def print_img_at_idx(self, idx):
"""Prints the image at index idx."""
img = self.images[idx]
print_img(img)
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]