-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfreeze_line_detection.py
More file actions
43 lines (32 loc) · 1.36 KB
/
freeze_line_detection.py
File metadata and controls
43 lines (32 loc) · 1.36 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
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""Freeze red-blue line detection model to use for inference. Change modelToLoad variable and export_path as needed
Example:
$ python freeze_line_detection.py
"""
import os
import numpy as np
import cv2
import keras.backend as K
import tensorflow as tf
import keras
import random
import keras.metrics
import train_blue_red
modelToLoad = './Model_KH_EXP/YUV_LOG_preprocess_3.hdf5'
export_path = './tensorflow-yolov3-models/models/Flu_audere_line/23'
if __name__ == "__main__":
keras.metrics.recall_m = train_blue_red.recall_m
keras.metrics.precision_m = train_blue_red.precision_m
keras.metrics.f1_m = train_blue_red.f1_m
tf.keras.backend.set_learning_phase(0) # Ignore dropout at inference
model = tf.keras.models.load_model(modelToLoad,custom_objects={"f1_m":keras.metrics.f1_m,"precision_m":keras.metrics.precision_m,"recall_m":keras.metrics.recall_m})
inputs = tf.saved_model.utils.build_tensor_info(model.inputs[0])
# Fetch the Keras session and save the model
# The signature definition is defined by the input and output tensors
# And stored with the default serving key
with tf.keras.backend.get_session() as sess:
tf.saved_model.simple_save(
sess,
export_path,
inputs={'input_image': model.inputs[0]},
outputs={"predictions":model.outputs[0]})