-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathutils.py
More file actions
45 lines (30 loc) · 936 Bytes
/
Copy pathutils.py
File metadata and controls
45 lines (30 loc) · 936 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import cv2
import numpy as np
import platform
__all__ = ["read_image", "preprocess_image", "read_eval_image_list", "read_image_list"]
def read_image(image_path):
if platform.system() == "Windows":
image_path = image_path.replace("*", "_")
img = cv2.imread(image_path)
return img
def preprocess_image(img, mean):
img = cv2.resize(img, (227, 227))
img = img - mean
img = img[1:225, 1:225, :]
img = np.expand_dims(img, axis=0)
return img
def read_eval_image_list(input_file):
image_paths = []
labels = []
with open(input_file) as f:
for line in f:
ip, l = line.strip().split(" ")
image_paths.append(ip)
labels.append(l)
return image_paths, labels
def read_image_list(input_file):
image_paths = []
with open(input_file) as f:
for line in f:
image_paths.append(line.strip())
return image_paths