-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
31 lines (25 loc) · 1 KB
/
util.py
File metadata and controls
31 lines (25 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
31
import json
import matplotlib.pyplot as plt
from json import dump
def skimage_hyperparam_tuning(im, func, callback, **hyperparams):
all_im = []
for i in range(len(list(hyperparams.values())[0])): # We assume the dictionary kwargs list has iterable values that are all of the same length
# Get curr_kwargs
curr_hyperparams = {key : hyperparams[key][i] for key in hyperparams}
curr_im = func(im, **curr_hyperparams)
all_im.append(curr_im)
# do callback
callback(curr_im, curr_hyperparams)
return curr_im
def skimage_imshow_complete_wrapper(im, curr_hyperparams):
ax = plt.gca()
skimage_imshow(im, ax, cmap = plt.cm.gray)
ax.set_title(json.dumps(curr_hyperparams))
plt.show()
def skimage_imshow(im, ax, **kwargs):
ax.imshow(im, **kwargs)
return ax
def image_path_gen(im_dir_path):
im_dir_path = os.path.realpath(im_dir_path)
for im_name in os.listdir(im_dir_path):
yield os.path.join(im_dir_path, im_name), im_name