parameters: (self, json_data)
return_statement: return result
docstring: Make inference with the current Session object and JSON request data.
          
      Args:
        json_data: The JSON serialized object with key and array data.
                   Example is {"model_version": 1, "data": {"keys": [[1.0], [2.0]], "features": [[10, 10, 10, 8, 6, 1, 8, 9, 1], [6, 2, 1, 1, 1, 1, 7, 1, 1]]}}.
      Return:
        The dictionary with key and array data.
        Example is {"keys": [[11], [2]], "softmax": [[0.61554497, 0.38445505], [0.61554497, 0.38445505]], "prediction": [0, 0]}.
docstring_summary: Make inference with the current Session object and JSON request data.
          
      Args:
        json_data: The JSON serialized object with key and array data.
                   Example is {"model_version": 1, "data": {"keys": [[1.0], [2.0]], "features": [[10, 10, 10, 8, 6, 1, 8, 9, 1], [6, 2, 1, 1, 1, 1, 7, 1, 1]]}}.
      Return:
        The dictionary with key and array data.
        Example is {"keys": [[11], [2]], "softmax": [[0.61554497, 0.38445505], [0.61554497, 0.38445505]], "prediction": [0, 0]}.
docstring_tokens: Make inference with the current Session object and JSON request data . Args : json_data : The JSON serialized object with key and array data . Example is { model_version : 1 data : { keys : [[ 1 . 0 ] [ 2 . 0 ]] features : [[ 10 10 10 8 6 1 8 9 1 ] [ 6 2 1 1 1 1 7 1 1 ]] }} . Return : The dictionary with key and array data . Example is { keys : [[ 11 ] [ 2 ]] softmax : [[ 0 . 61554497 0 . 38445505 ] [ 0 . 61554497 0 . 38445505 ]] prediction : [ 0 0 ] } .
function: def inference(self, json_data):
      """
      Make inference with the current Session object and JSON request data.
          
      Args:
        json_data: The JSON serialized object with key and array data.
                   Example is {"model_version": 1, "data": {"keys": [[1.0], [2.0]], "features": [[10, 10, 10, 8, 6, 1, 8, 9, 1], [6, 2, 1, 1, 1, 1, 7, 1, 1]]}}.
      Return:
        The dictionary with key and array data.
        Example is {"keys": [[11], [2]], "softmax": [[0.61554497, 0.38445505], [0.61554497, 0.38445505]], "prediction": [0, 0]}.
      """
  
      import mxnet as mx
      from mxnet.io import DataBatch
  
      # 1. Build inference data
  
      # TODO: Should use DataBatch or not
      # from mxnet.io import DataBatch
      # request_ndarray_data = json_data["data"]["data"]
      # request_mxnet_ndarray_data = [mx.nd.array(request_ndarray_data)]
      # batch_data = DataBatch(request_mxnet_ndarray_data)
  
      if self.has_signature_file:
        request_mxnet_ndarray_data = []
        batch_tuple_list = []
  
        for input_name in self.signature_input_names:
          # Example: [[7.0, 2.0]]
          request_ndarray_data = json_data["data"][input_name]
          batch_tuple_list.append(input_name)
          request_mxnet_ndarray_data.append(mx.nd.array(request_ndarray_data))
  
        # namedtuple('Batch', ['data'])
        Batch = namedtuple('Batch', batch_tuple_list)
        batch_data = Batch(request_mxnet_ndarray_data)
      else:
        Batch = namedtuple('Batch', ['data'])
        request_ndarray_data = json_data["data"]["data"]
        request_mxnet_ndarray_data = [mx.nd.array(request_ndarray_data)]
        batch_data = Batch(request_mxnet_ndarray_data)
  
      if json_data.get("preprocess", "false") != "false":
        if self.preprocess_function != None:
          batch_data = self.preprocess_function(batch_data)
          logger.debug("Preprocess to generate data: {}".format(batch_data))
        else:
          logger.warning("No preprocess function in model")
  
      # 2. Do inference
      start_time = time.time()
      self.mod.forward(batch_data)
      logger.debug("Inference time: {} s".format(time.time() - start_time))
  
      model_outputs = self.mod.get_outputs()
  
      prob = self.mod.get_outputs()[0].asnumpy()
      print(prob)
  
      # 3. Build return data
      result = {}
      for i, model_output in enumerate(model_outputs):
        # TODO: Get the real output name from ONNX model
        #result[self.signature_output_names[i]] = model_output.asnumpy()
        result["output_{}".format(i)] = model_output.asnumpy()
      logger.debug("Inference result: {}".format(result))
  
      if json_data.get("postprocess", "false") != "false":
        if self.postprocess_function != None:
          result = self.postprocess_function(result)
          logger.debug("Postprocess to generate data: {}".format(result))
        else:
          logger.warning("No postprocess function in model")
  
      return result
function_tokens: def inference ( self , json_data ) : import mxnet as mx from mxnet . io import DataBatch # 1. Build inference data # TODO: Should use DataBatch or not # from mxnet.io import DataBatch # request_ndarray_data = json_data["data"]["data"] # request_mxnet_ndarray_data = [mx.nd.array(request_ndarray_data)] # batch_data = DataBatch(request_mxnet_ndarray_data) if self . has_signature_file : request_mxnet_ndarray_data = [ ] batch_tuple_list = [ ] for input_name in self . signature_input_names : # Example: [[7.0, 2.0]] request_ndarray_data = json_data [ "data" ] [ input_name ] batch_tuple_list . append ( input_name ) request_mxnet_ndarray_data . append ( mx . nd . array ( request_ndarray_data ) ) # namedtuple('Batch', ['data']) Batch = namedtuple ( 'Batch' , batch_tuple_list ) batch_data = Batch ( request_mxnet_ndarray_data ) else : Batch = namedtuple ( 'Batch' , [ 'data' ] ) request_ndarray_data = json_data [ "data" ] [ "data" ] request_mxnet_ndarray_data = [ mx . nd . array ( request_ndarray_data ) ] batch_data = Batch ( request_mxnet_ndarray_data ) if json_data . get ( "preprocess" , "false" ) != "false" : if self . preprocess_function != None : batch_data = self . preprocess_function ( batch_data ) logger . debug ( "Preprocess to generate data: {}" . format ( batch_data ) ) else : logger . warning ( "No preprocess function in model" ) # 2. Do inference start_time = time . time ( ) self . mod . forward ( batch_data ) logger . debug ( "Inference time: {} s" . format ( time . time ( ) - start_time ) ) model_outputs = self . mod . get_outputs ( ) prob = self . mod . get_outputs ( ) [ 0 ] . asnumpy ( ) print ( prob ) # 3. Build return data result = { } for i , model_output in enumerate ( model_outputs ) : # TODO: Get the real output name from ONNX model #result[self.signature_output_names[i]] = model_output.asnumpy() result [ "output_{}" . format ( i ) ] = model_output . asnumpy ( ) logger . debug ( "Inference result: {}" . format ( result ) ) if json_data . get ( "postprocess" , "false" ) != "false" : if self . postprocess_function != None : result = self . postprocess_function ( result ) logger . debug ( "Postprocess to generate data: {}" . format ( result ) ) else : logger . warning ( "No postprocess function in model" ) return result