MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TFRequest

Class TFRequest

serving/processor/tests/flatbuf_test/python/pb/tf_request.py:9–103  ·  view source on GitHub ↗

Request for tensorflow services whose input data is in format of protobuf, privide methods to generate the required protobuf object, and serialze it to string

Source from the content-addressed store, hash-verified

7
8
9class TFRequest(Request):
10 """
11 Request for tensorflow services whose input data is in format of protobuf,
12 privide methods to generate the required protobuf object, and serialze it to string
13 """
14 DT_FLOAT = tf_pb.DT_FLOAT
15 DT_DOUBLE = tf_pb.DT_DOUBLE
16 DT_INT8 = tf_pb.DT_INT8
17 DT_INT16 = tf_pb.DT_INT16
18 DT_INT32 = tf_pb.DT_INT32
19 DT_INT64 = tf_pb.DT_INT64
20 DT_UINT8 = tf_pb.DT_UINT8
21 DT_UINT16 = tf_pb.DT_UINT16
22 DT_QINT8 = tf_pb.DT_QINT8
23 DT_QUINT8 = tf_pb.DT_QUINT8
24 DT_QINT16 = tf_pb.DT_QINT16
25 DT_QUINT16 = tf_pb.DT_QUINT16
26 DT_QINT32 = tf_pb.DT_QINT32
27 DT_STRING = tf_pb.DT_STRING
28 DT_BOOL = tf_pb.DT_BOOL
29
30 def __init__(self, signature_name=None):
31 self.request_data = tf_pb.PredictRequest()
32 self.signature_name = signature_name
33
34 def __str__(self):
35 return self.request_data
36
37 def set_signature_name(self, singature_name):
38 """
39 Set the signature name of the model
40 :param singature_name: signature name of the model
41 """
42 self.signature_name = singature_name
43
44 def add_feed(self, input_name, shape, content_type, content):
45 """
46 Add input data for the request, a tensorflow model may have many inputs with different
47 data types, this methods set data for one of the input with the specified name 'input_name'
48 :param input_name: name of the input to be set
49 :param shape: shape of the input tensor in format of array, such as [1,784]
50 :param content_type: type of the input tensor, can be one of the predefined data type, such as TFRequest.DT_FLOAT
51 :param content: data content of the input tensor, which is expanded to one-dimension array, such as [1,2,3,4,5]
52 """
53 self.request_data.signature_name = self.signature_name
54 self.request_data.inputs[input_name].dtype = content_type
55 self.request_data.inputs[input_name].array_shape.dim.extend(shape)
56 integer_types = [
57 tf_pb.DT_INT8,
58 tf_pb.DT_INT16,
59 tf_pb.DT_INT32 ,
60 tf_pb.DT_UINT8 ,
61 tf_pb.DT_UINT16,
62 tf_pb.DT_QINT8,
63 tf_pb.DT_QINT16,
64 tf_pb.DT_QINT32,
65 tf_pb.DT_QUINT8,
66 tf_pb.DT_QUINT16,

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected