def test_prepare_get_metadata_output(): inputs = {'tensor_input': Layer('FP32', (1, 1, 1), 'NCHW')} outputs = {'tensor_output': Layer('FP32', (1, 1, 1), 'NCHW')} model_keys = {'inputs': {'name': 'tensor_input'}, 'outputs': {'output_name': 'tensor_output'}} output = prepare_get_metadata_output( inputs=inputs, outputs=outputs, model_keys=model_keys) assert "tensorflow/serving/predict" == output.method_name
def test_prepare_get_metadata_output(): inputs = {'tensor': (1, 1, 1)} outputs = ['tensor_output'] model_keys = { 'inputs': { 'name': 'tensor' }, 'outputs': { 'output_name': 'tensor_output' } } output = prepare_get_metadata_output(inputs=inputs, outputs=outputs, model_keys=model_keys) assert "tensorflow/serving/predict" == output.method_name
def GetModelMetadata(self, request, context): # check if model with was requested # is available on server with proper version logger.debug("MODEL_METADATA, get request: {}".format(request)) model_name = request.model_spec.name requested_version = request.model_spec.version.value valid_model_spec, version = check_availability_of_requested_model( models=self.models, requested_version=requested_version, model_name=model_name) if not valid_model_spec: context.set_code(StatusCode.NOT_FOUND) context.set_details( WRONG_MODEL_SPEC.format(model_name, requested_version)) logger.debug("MODEL_METADATA, invalid model spec from request") return get_model_metadata_pb2.GetModelMetadataResponse() target_engine = self.models[model_name].engines[version] target_engine.in_use.acquire() metadata_signature_requested = request.metadata_field[0] if 'signature_def' != metadata_signature_requested: context.set_code(StatusCode.INVALID_ARGUMENT) context.set_details( INVALID_METADATA_FIELD.format(metadata_signature_requested)) logger.debug("MODEL_METADATA, invalid signature def") target_engine.in_use.release() return get_model_metadata_pb2.GetModelMetadataResponse() inputs = target_engine.net.inputs outputs = target_engine.net.outputs signature_def = prepare_get_metadata_output( inputs=inputs, outputs=outputs, model_keys=target_engine.model_keys) response = get_model_metadata_pb2.GetModelMetadataResponse() model_data_map = get_model_metadata_pb2.SignatureDefMap() model_data_map.signature_def['serving_default'].CopyFrom(signature_def) response.metadata['signature_def'].Pack(model_data_map) response.model_spec.name = model_name response.model_spec.version.value = version logger.debug("MODEL_METADATA created a response for {} - {}".format( model_name, version)) target_engine.in_use.release() return response
def on_get(self, req, resp, model_name, requested_version=0): logger.debug("MODEL_METADATA, get request: {}, {}".format( model_name, requested_version)) valid_model_spec, version = check_availability_of_requested_model( models=self.models, requested_version=requested_version, model_name=model_name) if not valid_model_spec: resp.status = falcon.HTTP_NOT_FOUND logger.debug("MODEL_METADATA, invalid model spec from request") err_out_json = { 'error': WRONG_MODEL_SPEC.format(model_name, requested_version) } resp.body = json.dumps(err_out_json) return target_engine = self.models[model_name].engines[version] target_engine.in_use.acquire() inputs = target_engine.net.inputs outputs = target_engine.net.outputs signature_def = prepare_get_metadata_output( inputs=inputs, outputs=outputs, model_keys=target_engine.model_keys) response = get_model_metadata_pb2.GetModelMetadataResponse() model_data_map = get_model_metadata_pb2.SignatureDefMap() model_data_map.signature_def['serving_default'].CopyFrom(signature_def) response.metadata['signature_def'].Pack(model_data_map) response.model_spec.name = model_name response.model_spec.version.value = version logger.debug("MODEL_METADATA created a response for {} - {}".format( model_name, version)) target_engine.in_use.release() resp.status = falcon.HTTP_200 resp.body = MessageToJson(response)