-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmayo_util.py
More file actions
28 lines (21 loc) · 782 Bytes
/
mayo_util.py
File metadata and controls
28 lines (21 loc) · 782 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
"""Helper function for reading and randomizing order of training data."""
import os
import random
# Path to data folder
DATA_FOLDER = "Give path to data folder"
class FileLoader(object):
"""Helper class for reading the data."""
def __init__(self, folder, exclude):
self.folder = folder
self.exclude = exclude
self.load_files()
def load_files(self):
self.files = []
for (dirpath, dirnames, filenames) in os.walk(self.folder):
self.files.extend([os.path.join(self.folder, fi) for fi in filenames
if not fi.startswith(self.exclude)])
random.shuffle(self.files)
def next_file(self):
if not self.files:
self.load_files()
return self.files.pop()