-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathutils.py
52 lines (44 loc) · 1.35 KB
/
utils.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
45
46
47
48
49
50
51
52
import os
import numpy as np
import cv2
import json
from metrics import *
from glob import glob
from tensorflow.keras.utils import CustomObjectScope
from tensorflow.keras.models import load_model
def create_dir(path):
""" Create a directory. """
try:
if not os.path.exists(path):
os.makedirs(path)
except OSError:
print(f"Error: creating directory with name {path}")
def read_data(x, y):
""" Read the image and mask from the given path. """
image = cv2.imread(x, cv2.IMREAD_COLOR)
mask = cv2.imread(y, cv2.IMREAD_COLOR)
return image, mask
def read_params():
""" Reading the parameters from the JSON file."""
with open("params.json", "r") as f:
data = f.read()
params = json.loads(data)
return params
def load_data(path):
""" Loading the data from the given path. """
images_path = os.path.join(path, "image/*")
masks_path = os.path.join(path, "mask/*")
images = glob(images_path)
masks = glob(masks_path)
return images, masks
def load_model_weight(path):
with CustomObjectScope({
'dice_loss': dice_loss,
'dice_coef': dice_coef,
'bce_dice_loss': bce_dice_loss,
'focal_loss': focal_loss,
'tversky_loss': tversky_loss,
'focal_tversky': focal_tversky
}):
model = load_model(path)
return model