-
Notifications
You must be signed in to change notification settings - Fork 9
/
utils.py
31 lines (27 loc) · 871 Bytes
/
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
import os
import json
from sklearn.utils import shuffle
import tensorflow as tf
from tensorflow.keras.utils import CustomObjectScope
from tensorflow.keras.metrics import Recall, Precision, MeanIoU
from tensorflow.keras.optimizers import Adam
from metrics import iou, dice_coef, dice_loss, bce_dice_loss
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 shuffling(x, y):
x, y = shuffle(x, y, random_state=42)
return x, y
def load_model_file(path):
with CustomObjectScope({
'iou':iou,
'dice_coef':dice_coef,
'dice_loss':dice_loss,
'bce_dice_loss': bce_dice_loss
}):
model = tf.keras.models.load_model(path)
return model