File size: 382 Bytes
fe8e241
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
import numpy as np
import tensorflow as tf

def predict_saved_model(model_dir, input_name, x):
    model = tf.saved_model.load(model_dir)
    serving = model.signatures["serving_default"]
    x = np.asarray(x, dtype=np.float32)
    with tf.device("/GPU:0"):
        out = serving(**{input_name: tf.constant(x)})
    first_key = list(out.keys())[0]
    return out[first_key].numpy()