-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_loader.py
44 lines (30 loc) · 1.17 KB
/
data_loader.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
import os
import time
import pickle
import json
from sklearn.externals import joblib
from glob import glob
"""
Script used to load and save the data used for training
"""
def load_dataset(cars_folder = os.path.join('data', 'vehicles'),
notcars_folder = os.path.join('data', 'non-vehicles')):
print('Loading dataset...')
t1 = time.time()
cars_ptn = os.path.join(cars_folder, '**', '*.png')
notcars_ptn = os.path.join(notcars_folder, '**', '*.png')
cars = glob(cars_ptn, recursive=True)
notcars = glob(notcars_ptn, recursive=True)
t2 = time.time()
print('Loading dataset...DONE ({} s, Car images: {}, Not-Car images: {})'.format(round(t2 - t1, 2), len(cars), len(notcars)))
return cars, notcars
def load_config(file = 'search_params.json'):
with open(file) as f:
data = json.load(f)
return data
def save_model(model, model_file = os.path.join('models', 'model.p')):
print('Saving model to {}...'.format(model_file))
joblib.dump(model, model_file)
def load_model(model_file = os.path.join('models', 'model.p')):
print('Loading model from {}...'.format(model_file))
return joblib.load(model_file)