-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (27 loc) · 1 KB
/
Copy pathutils.py
File metadata and controls
30 lines (27 loc) · 1 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
import os
import numpy as np
from sklearn.preprocessing import MinMaxScaler
def generate_batches(dataParser, train=True):
while True:
if train:
batch_ids = np.random.choice(dataParser.training_ids, dataParser.batch_size, replace=False)
else:
batch_ids = np.random.choice(dataParser.validation_ids, dataParser.batch_size*2, replace=False)
images, labels = dataParser.get_batch(batch_ids)
yield(images, labels)
def label_files_with_names(train_path):
file_names=[]
for file_name in os.listdir(train_path):
result=0
if "cat" in file_name:
result=1
file_names.append((os.path.join(train_path,file_name), result))
return file_names
def normalize_rgb(img):
im = img.shape
img = img.reshape((img.shape[0]*img.shape[1]), img.shape[2])
scaler = MinMaxScaler()
scaler = scaler.fit(img)
img = scaler.fit_transform(img)
img = img.reshape(im[0], im[1], im[2])
return img