-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtensorrt_model.py
More file actions
40 lines (24 loc) · 957 Bytes
/
Copy pathtensorrt_model.py
File metadata and controls
40 lines (24 loc) · 957 Bytes
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
import tensorflow as tf
from tensorflow.python.saved_model import tag_constants
import numpy as np
class TensorRTModel:
def __init__(self, input_saved_model="tensorrt-model"):
saved_model_loaded = tf.saved_model.load(input_saved_model, tags=[tag_constants.SERVING])
signature_keys = list(saved_model_loaded.signatures.keys())
print(signature_keys)
self.infer = saved_model_loaded.signatures['serving_default']
print(self.infer.structured_outputs)
self.name = "TensorRT"
def predict(self, input_board):
t = tf.constant(input_board.astype(np.float32))
result = self.infer(t)
return (result['moves'].numpy(), result['value'].numpy())
# Test
if __name__ == "__main__":
m = TensorRTModel()
from chess import Board
from chess_input import Repr2D
r = Repr2D()
i = r.board_to_array(Board())
i = np.expand_dims(i, axis=0)
print(m.predict(i))