def _communicate(self, request, debug=False): """Gets response and logs messages if need to. Args: request: protocol_pb2.Request debug: boolean, if True and response contains inference result, print up to the first 10 elements of each returned vector. Returns: protocol_pb2.Response """ response = protocol_pb2.Response() response.ParseFromString( self._transport.send(request.SerializeToString())) if response.status.code != protocol_pb2.Response.Status.OK: raise InferenceException(response.status.message) if debug: # Print up to the first 10 elements of each returned vector. for name, tensor in response.result.tensors.items(): data = tensor.data[0:10] logging.info('First %d elements of output tensor:', len(data)) for index, value in enumerate(data): logging.info(' %s[%d] = %f', name, index, value) return response
def _communicate(self, request, debug=False): """Gets response and logs messages if need to. Args: request: protocol_pb2.Request debug: boolean, if True and response contains inference result, print up to the first 10 elements of each returned vector. Returns: protocol_pb2.Response """ response = protocol_pb2.Response() response.ParseFromString(self._transport.send(request.SerializeToString())) # TODO: throw exception when error happens for error in response.errors: if error.type == protocol_pb2.Response.Error.INFO: logging.info(error.msg) elif error.type == protocol_pb2.Response.Error.WARNING: logging.warning(error.msg) elif error.type == protocol_pb2.Response.Error.ERROR: logging.error(error.msg) else: logging.error('Unknown error type: %d', error.type) if debug: # Print up to the first 10 elements of each returned vector. for name, tensor in response.result.tensors.items(): data = tensor.data[0:10] logging.info('First %d elements of output tensor:', len(data)) for index, value in enumerate(data): logging.info(' %s[%d] = %f', name, index, value) return response
def _communicate_bytes(self, request_bytes, timeout=None): response = pb2.Response() response.ParseFromString( self._transport.send(request_bytes, timeout=timeout)) if response.status.code != pb2.Response.Status.OK: raise InferenceException(response.status.message) return response
def _communicate(self, request): """Gets response and logs messages if need to. Args: request: protocol_pb2.Request Returns: protocol_pb2.Response """ response = protocol_pb2.Response() response.ParseFromString(self._transport.send(request.SerializeToString())) if response.status.code != protocol_pb2.Response.Status.OK: raise InferenceException(response.status.message) return response
def get_invalid(spicomm, size, timeout=None): response = pb2.Response() response.ParseFromString(spicomm.transact(b'A' * size, timeout)) return response
def get_camera_state(spicomm, timeout=None): request = pb2.Request(get_camera_state=pb2.Request.GetCameraState()) response = pb2.Response() response.ParseFromString( spicomm.transact(request.SerializeToString(), timeout)) return response