def test_latest_version(self, download_two_model_versions, get_test_dir, start_server_update_flow_latest, create_channel_for_update_flow_latest): resnet_v1, resnet_v2 = download_two_model_versions dir = get_test_dir + '/saved_models/' + 'update/' resnet_v1_copy_dir = copy_model(resnet_v1, 1, dir) time.sleep(8) stub = create_channel_for_update_flow_latest print("Getting info about resnet model") model_name = 'resnet' out_name = 'resnet_v1_50/predictions/Reshape_1' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [1, 1000]}} request = get_model_metadata(model_name=model_name) response = stub.GetModelMetadata(request, 10) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata shutil.rmtree(resnet_v1_copy_dir) resnet_v2_copy_dir = copy_model(resnet_v2, 2, dir) time.sleep(3) out_name = 'resnet_v2_50/predictions/Reshape_1' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [1, 1001]}} request = get_model_metadata(model_name=model_name) response = stub.GetModelMetadata(request, 10) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata shutil.rmtree(resnet_v2_copy_dir)
def test_latest_version_rest(self, download_two_model_versions, get_test_dir, start_server_update_flow_latest): resnet_v1, resnet_v2 = download_two_model_versions dir = get_test_dir + '/saved_models/' + 'update/' resnet_v1_copy_dir = copy_model(resnet_v1, 1, dir) time.sleep(8) print("Getting info about resnet model") model_name = 'resnet' out_name = 'resnet_v1_50/predictions/Reshape_1' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [1, 1000]}} rest_url = 'http://localhost:5562/v1/models/resnet/metadata' response = get_model_metadata_response_rest(rest_url) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata shutil.rmtree(resnet_v1_copy_dir) resnet_v2_copy_dir = copy_model(resnet_v2, 2, dir) time.sleep(3) out_name = 'resnet_v2_50/predictions/Reshape_1' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [1, 1001]}} response = get_model_metadata_response_rest(rest_url) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata shutil.rmtree(resnet_v2_copy_dir)
def test_get_model_metadata(self, resnet_2_out_model_downloader, create_channel_for_port_mapping_server, start_server_with_mapping): print("Downloaded model files:", resnet_2_out_model_downloader) stub = create_channel_for_port_mapping_server model_name = 'resnet_2_out' expected_input_metadata = { 'new_key': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = { 'mask': { 'dtype': 1, 'shape': [1, 2048, 7, 7] }, 'output': { 'dtype': 1, 'shape': [1, 2048, 7, 7] } } request = get_model_metadata(model_name=model_name) response = stub.GetModelMetadata(request, 10) print("response", response) input_metadata, output_metadata = model_metadata_response( response=response) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_get_model_metadata_rest(self, download_two_model_versions, start_server_multi_model): print("Downloaded model files:", download_two_model_versions) urls = ['http://localhost:5561/v1/models/resnet/metadata', 'http://localhost:5561/v1/models/resnet/versions/1/metadata'] expected_outputs_metadata = \ [{'resnet_v2_50/predictions/Reshape_1': {'dtype': 1, 'shape': [1, 1001]}}, {'resnet_v1_50/predictions/Reshape_1': {'dtype': 1, 'shape': [1, 1000]}} ] for x in range(len(urls)): print("Getting info about resnet model version:".format( urls[x])) model_name = 'resnet' expected_input_metadata = {'input': {'dtype': 1, 'shape': [1, 3, 224, 224]}} expected_output_metadata = expected_outputs_metadata[x] response = get_model_metadata_response_rest(urls[x]) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_get_model_metadata(self, resnet_8_batch_model_downloader, start_server_batch_model, create_channel_for_batching_server): print("Downloaded model files:", resnet_8_batch_model_downloader) stub = create_channel_for_batching_server model_name = 'resnet' out_name = 'resnet_v1_50/predictions/Reshape_1' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [8, 3, 224, 224] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [8, 1000]}} request = get_model_metadata(model_name='resnet') response = stub.GetModelMetadata(request, 10) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_get_model_metadata(self, start_server_single_model_from_gc, create_channel_for_port_single_server): result = start_server_single_model_from_gc print("docker starting status:", result) time.sleep(30) # Waiting for inference service to load models assert result == 0, "docker container was not started successfully" stub = create_channel_for_port_single_server model_name = 'resnet' out_name = 'resnet_v1_50/predictions/Reshape_1' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [1, 1, 1]}} request = get_model_metadata(model_name='resnet') response = stub.GetModelMetadata(request, 10) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_get_model_metadata_rest(self, resnet_2_out_model_downloader, start_server_with_mapping): print("Downloaded model files:", resnet_2_out_model_downloader) model_name = 'resnet_2_out' expected_input_metadata = { 'new_key': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = { 'mask': { 'dtype': 1, 'shape': [1, 2048, 7, 7] }, 'output': { 'dtype': 1, 'shape': [1, 2048, 7, 7] } } rest_url = 'http://localhost:5556/v1/models/resnet_2_out/metadata' response = get_model_metadata_response_rest(rest_url) print("response", response) input_metadata, output_metadata = model_metadata_response( response=response) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_get_model_metadata(self, download_two_model_versions, start_server_multi_model, create_channel_for_port_multi_server): print("Downloaded model files:", download_two_model_versions) # Connect to grpc service stub = create_channel_for_port_multi_server versions = [None, 1] expected_outputs_metadata = \ [{'resnet_v2_50/predictions/Reshape_1': {'dtype': 1, 'shape': [1, 1001]}}, {'resnet_v1_50/predictions/Reshape_1': {'dtype': 1, 'shape': [1, 1000]}} ] for x in range(len(versions)): print("Getting info about resnet model version:".format( versions[x])) model_name = 'resnet' expected_input_metadata = {'input': {'dtype': 1, 'shape': [1, 3, 224, 224]}} expected_output_metadata = expected_outputs_metadata[x] request = get_model_metadata(model_name='resnet', version=versions[x]) response = stub.GetModelMetadata(request, 10) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_get_model_metadata(self, download_two_models, start_server_multi_model, create_channel_for_port_multi_server): """ <b>Description</b> Execute inference request using gRPC interface hosting multiple models <b>input data</b> - directory with 2 models in IR format - docker image <b>fixtures used</b> - model downloader - input data downloader - service launching <b>Expected results</b> - response contains proper response about model metadata for both models set in config file: model resnet_v1_50, pnasnet_large - both served models handles appropriate input formats """ print("Downloaded model files:", download_two_models) # Connect to grpc service stub = create_channel_for_port_multi_server versions = [None, 1] expected_outputs_metadata = \ [{'resnet_v2_50/predictions/Reshape_1': {'dtype': 1, 'shape': [1, 1001]}}, {'resnet_v1_50/predictions/Reshape_1': {'dtype': 1, 'shape': [1, 1000]}} ] for x in range(len(versions)): print("Getting info about resnet model version:".format( versions[x])) model_name = 'resnet' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = expected_outputs_metadata[x] request = get_model_metadata(model_name='resnet', version=versions[x]) response = stub.GetModelMetadata(request, 10) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_get_model_metadata_rest(self, download_two_models, start_server_multi_model): """ <b>Description</b> Execute inference request using REST API interface hosting multiple models <b>input data</b> - directory with 2 models in IR format - docker image <b>fixtures used</b> - model downloader - input data downloader - service launching <b>Expected results</b> - response contains proper response about model metadata for both models set in config file: model resnet_v1_50, pnasnet_large - both served models handles appropriate input formats """ print("Downloaded model files:", download_two_models) urls = [ 'http://localhost:5561/v1/models/resnet/metadata', 'http://localhost:5561/v1/models/resnet/versions/1/metadata' ] expected_outputs_metadata = \ [{'resnet_v2_50/predictions/Reshape_1': {'dtype': 1, 'shape': [1, 1001]}}, {'resnet_v1_50/predictions/Reshape_1': {'dtype': 1, 'shape': [1, 1000]}} ] for x in range(len(urls)): print("Getting info about resnet model version:".format(urls[x])) model_name = 'resnet' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = expected_outputs_metadata[x] response = get_model_metadata_response_rest(urls[x]) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_get_model_metadata(self, start_server_single_model_from_gc, create_channel_for_port_single_server): stub = create_channel_for_port_single_server model_name = 'resnet' out_name = 'resnet_v1_50/predictions/Reshape_1' expected_input_metadata = {'input': {'dtype': 1, 'shape': [1, 3, 224, 224]}} expected_output_metadata = {out_name: {'dtype': 1, 'shape': [1, 1000]}} request = get_model_metadata(model_name='resnet') response = stub.GetModelMetadata(request, 10) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_get_model_metadata_rest(self, resnet_8_batch_model_downloader, start_server_batch_model): print("Downloaded model files:", resnet_8_batch_model_downloader) model_name = 'resnet' out_name = 'resnet_v1_50/predictions/Reshape_1' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [8, 3, 224, 224] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [8, 1000]}} rest_url = 'http://localhost:5557/v1/models/resnet/metadata' response = get_model_metadata_response_rest(rest_url) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_get_model_metadata(self, resnet_2_out_model_downloader, create_channel_for_port_mapping_server, start_server_with_mapping): print("Downloaded model files:", resnet_2_out_model_downloader) result = start_server_with_mapping print("docker starting status:", result) time.sleep(30) # Waiting for inference service to load models assert result == 0, "docker container was not started successfully" stub = create_channel_for_port_mapping_server model_name = 'resnet_2_out' expected_input_metadata = { 'new_key': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = { 'mask': { 'dtype': 1, 'shape': [1, 2048, 7, 7] }, 'output': { 'dtype': 1, 'shape': [1, 2048, 7, 7] } } request = get_model_metadata(model_name=model_name) response = stub.GetModelMetadata(request, 10) print("response", response) input_metadata, output_metadata = model_metadata_response( response=response) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_get_model_metadata_rest(self, model_version_policy_models, start_server_model_ver_policy, model_name, throw_error): """ <b>Description</b> Execute GetModelMetadata request using gRPC interface hosting multiple models <b>input data</b> - directory with 2 models in IR format - docker image <b>fixtures used</b> - model downloader - input data downloader - service launching <b>Expected results</b> - response contains proper response about model metadata for both models set in config file: model resnet_v1_50, pnasnet_large - both served models handles appropriate input formats """ print("Downloaded model files:", model_version_policy_models) print("Getting info about resnet model") versions = [1, 2, 3] expected_outputs_metadata = [{ 'resnet_v1_50/predictions/Reshape_1': { 'dtype': 1, 'shape': [1, 1000] } }, { 'resnet_v2_50/predictions/Reshape_1': { 'dtype': 1, 'shape': [1, 1001] } }, { 'mask': { 'dtype': 1, 'shape': [1, 2048, 7, 7] }, 'output': { 'dtype': 1, 'shape': [1, 2048, 7, 7] } }] expected_inputs_metadata = [{ 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } }, { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } }, { 'new_key': { 'dtype': 1, 'shape': [1, 3, 224, 224] } }] for x in range(len(versions)): print("Getting info about resnet model version:".format( versions[x])) expected_input_metadata = expected_inputs_metadata[x] expected_output_metadata = expected_outputs_metadata[x] rest_url = 'http://localhost:5560/v1/models/{}/' \ 'versions/{}/metadata'.format(model_name, versions[x]) result = requests.get(rest_url) print(result.text) if not throw_error[x]: output_json = result.text metadata_pb = get_model_metadata_pb2.\ GetModelMetadataResponse() response = Parse(output_json, metadata_pb, ignore_unknown_fields=False) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata else: assert 404 == result.status_code
def test_get_model_metadata(self, model_version_policy_models, start_server_model_ver_policy, create_channel_for_model_ver_pol_server, model_name, throw_error): """ <b>Description</b> Execute GetModelMetadata request using gRPC interface hosting multiple models <b>input data</b> - directory with 2 models in IR format - docker image <b>fixtures used</b> - model downloader - input data downloader - service launching <b>Expected results</b> - response contains proper response about model metadata for both models set in config file: model resnet_v1_50, pnasnet_large - both served models handles appropriate input formats """ print("Downloaded model files:", model_version_policy_models) # Connect to grpc service stub = create_channel_for_model_ver_pol_server print("Getting info about resnet model") versions = [1, 2, 3] expected_outputs_metadata = [{ 'resnet_v1_50/predictions/Reshape_1': { 'dtype': 1, 'shape': [1, 1000] } }, { 'resnet_v2_50/predictions/Reshape_1': { 'dtype': 1, 'shape': [1, 1001] } }, { 'mask': { 'dtype': 1, 'shape': [1, 2048, 7, 7] }, 'output': { 'dtype': 1, 'shape': [1, 2048, 7, 7] } }] expected_inputs_metadata = [{ 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } }, { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } }, { 'new_key': { 'dtype': 1, 'shape': [1, 3, 224, 224] } }] for x in range(len(versions)): print("Getting info about resnet model version:".format( versions[x])) expected_input_metadata = expected_inputs_metadata[x] expected_output_metadata = expected_outputs_metadata[x] request = get_model_metadata(model_name=model_name, version=versions[x]) if not throw_error[x]: response = stub.GetModelMetadata(request, 10) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata else: with pytest.raises(AbortionError): response = stub.GetModelMetadata(request, 10)
def test_specific_version_rest(self, download_two_model_versions, resnet_2_out_model_downloader, get_test_dir, start_server_update_flow_specific): resnet_v1, resnet_v2 = download_two_model_versions resnet_2_out = resnet_2_out_model_downloader dir = get_test_dir + '/saved_models/' + 'update/' resnet_v1_copy_dir = copy_model(resnet_v1, 1, dir) resnet_2_out_copy_dir = copy_model(resnet_2_out, 4, dir) time.sleep(8) # Available versions: 1, 4 print("Getting info about resnet model") model_name = 'resnet' out_name_v1 = 'resnet_v1_50/predictions/Reshape_1' expected_input_metadata_v1 = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata_v1 = { out_name_v1: { 'dtype': 1, 'shape': [1, 1000] } } rest_url_latest = 'http://localhost:5563/v1/models/resnet/' \ 'versions/1/metadata' response = get_model_metadata_response_rest(rest_url_latest) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata_v1 == input_metadata assert expected_output_metadata_v1 == output_metadata rest_url = 'http://localhost:5563/v1/models/resnet/metadata' response_latest = get_model_metadata_response_rest(rest_url) print("response", response_latest) input_metadata_latest, output_metadata_latest = \ model_metadata_response(response=response_latest) rest_url_v4 = 'http://localhost:5563/v1/models/resnet/' \ 'versions/1/metadata' response_v4 = get_model_metadata_response_rest(rest_url_v4) print("response", response_v4) input_metadata_v4, output_metadata_v4 = model_metadata_response( response=response_latest) assert response_v4.model_spec.name == response_latest.model_spec.name assert input_metadata_v4 == input_metadata_latest assert output_metadata_v4 == output_metadata_latest # Model status check rest_status_url = 'http://localhost:5563/v1/models/resnet' status_response = get_model_status_response_rest(rest_status_url) versions_statuses = status_response.model_version_status assert len(versions_statuses) == 2 for version_status in versions_statuses: assert version_status.version in [1, 4] assert version_status.state == ModelVersionState.AVAILABLE assert version_status.status.error_code == ErrorCode.OK assert version_status.status.error_message == _ERROR_MESSAGE[ ModelVersionState.AVAILABLE][ErrorCode.OK] ### shutil.rmtree(resnet_2_out_copy_dir) resnet_v2_copy_dir = copy_model(resnet_v2, 3, dir) time.sleep(10) # Available versions: 1, 3 rest_url = 'http://localhost:5563/v1/models/resnet/metadata' response_latest = get_model_metadata_response_rest(rest_url) print("response", response_latest) input_metadata_latest, output_metadata_latest = \ model_metadata_response(response=response_latest) rest_url_v3 = 'http://localhost:5563/v1/models/resnet/' \ 'versions/3/metadata' response_v3 = get_model_metadata_response_rest(rest_url_v3) print("response", response_v3) input_metadata_v3, output_metadata_v3 = model_metadata_response( response=response_v3) assert response_v3.model_spec.name == response_latest.model_spec.name assert input_metadata_v3 == input_metadata_latest assert output_metadata_v3 == output_metadata_latest # Model status check rest_status_url = 'http://localhost:5563/v1/models/resnet' status_response = get_model_status_response_rest(rest_status_url) versions_statuses = status_response.model_version_status assert len(versions_statuses) == 3 for version_status in versions_statuses: assert version_status.version in [1, 3, 4] if version_status.version == 4: assert version_status.state == ModelVersionState.END assert version_status.status.error_code == ErrorCode.OK assert version_status.status.error_message == _ERROR_MESSAGE[ ModelVersionState.END][ErrorCode.OK] elif version_status.version == 1 or version_status.version == 3: assert version_status.state == ModelVersionState.AVAILABLE assert version_status.status.error_code == ErrorCode.OK assert version_status.status.error_message == _ERROR_MESSAGE[ ModelVersionState.AVAILABLE][ErrorCode.OK] ### # Available versions: 1, 3, 4 resnet_2_out_copy_dir = copy_model(resnet_2_out, 4, dir) time.sleep(10) rest_url_v1 = 'http://localhost:5563/v1/models/resnet/' \ 'versions/1/metadata' response_v1 = get_model_metadata_response_rest(rest_url_v1) input_metadata_v1, output_metadata_v1 = model_metadata_response( response=response_v1) assert model_name == response_v1.model_spec.name assert expected_input_metadata_v1 == input_metadata_v1 assert expected_output_metadata_v1 == output_metadata_v1 out_name_v3 = 'resnet_v2_50/predictions/Reshape_1' expected_input_metadata_v3 = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata_v3 = { out_name_v3: { 'dtype': 1, 'shape': [1, 1001] } } rest_url_v3 = 'http://localhost:5563/v1/models/resnet/' \ 'versions/3/metadata' response_v3 = get_model_metadata_response_rest(rest_url_v3) input_metadata_v3, output_metadata_v3 = model_metadata_response( response=response_v3) assert model_name == response_v3.model_spec.name assert expected_input_metadata_v3 == input_metadata_v3 assert expected_output_metadata_v3 == output_metadata_v3 expected_input_metadata_v4 = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata_v4 = { 'res5c_branch2c1': { 'dtype': 1, 'shape': [1, 2048, 7, 7] }, 'res5c_branch2c2': { 'dtype': 1, 'shape': [1, 2048, 7, 7] } } rest_url = 'http://localhost:5563/v1/models/resnet/metadata' response_v4 = get_model_metadata_response_rest(rest_url) input_metadata_v4, output_metadata_v4 = model_metadata_response( response=response_v4) assert model_name == response_v4.model_spec.name assert expected_input_metadata_v4 == input_metadata_v4 assert expected_output_metadata_v4 == output_metadata_v4 # Model status check rest_status_url = 'http://localhost:5563/v1/models/resnet' status_response = get_model_status_response_rest(rest_status_url) versions_statuses = status_response.model_version_status assert len(versions_statuses) == 3 for version_status in versions_statuses: assert version_status.version in [1, 3, 4] assert version_status.state == ModelVersionState.AVAILABLE assert version_status.status.error_code == ErrorCode.OK assert version_status.status.error_message == _ERROR_MESSAGE[ ModelVersionState.AVAILABLE][ErrorCode.OK] ### shutil.rmtree(resnet_v2_copy_dir) shutil.rmtree(resnet_v1_copy_dir) shutil.rmtree(resnet_2_out_copy_dir) time.sleep(10)
def test_get_model_metadata(self, download_two_models, start_server_multi_model, create_channel_for_port_multi_server): """ <b>Description</b> Execute inference request using gRPC interface hosting multiple models <b>input data</b> - directory with 2 models in IR format - docker image <b>fixtures used</b> - model downloader - input data downloader - service launching <b>Expected results</b> - response contains proper response about model metadata for both models set in config file: model resnet_v1_50, pnasnet_large - both served models handles appropriate input formats """ print("Downloaded model files:", download_two_models) # Starting docker with ie-serving result = start_server_multi_model print("docker starting multi model server status:", result) time.sleep(30) # Waiting for inference service to load models assert result == 0, "docker container was not started successfully" # Connect to grpc service stub = create_channel_for_port_multi_server print("Getting info about resnet model") model_name = 'resnet_V1_50' out_name = 'resnet_v1_50/predictions/Reshape_1' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [1, 1, 1]}} request = get_model_metadata(model_name='resnet_V1_50') response = stub.GetModelMetadata(request, 10) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata model_name = 'pnasnet_large' out_name = 'final_layer/predictions' request = get_model_metadata(model_name='pnasnet_large') response = stub.GetModelMetadata(request, 10) input_metadata, output_metadata = model_metadata_response( response=response) expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 331, 331] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [1, 1, 1]}} print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata
def test_latest_version_rest(self, download_two_model_versions, get_test_dir, start_server_update_flow_latest): resnet_v1, resnet_v2 = download_two_model_versions dir = get_test_dir + '/saved_models/' + 'update/' resnet_v1_copy_dir = copy_model(resnet_v1, 1, dir) time.sleep(8) print("Getting info about resnet model") model_name = 'resnet' out_name = 'resnet_v1_50/predictions/Reshape_1' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [1, 1000]}} rest_url = 'http://localhost:5562/v1/models/resnet/metadata' response = get_model_metadata_response_rest(rest_url) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata # Model status check before update rest_status_url = 'http://localhost:5562/v1/models/resnet' status_response = get_model_status_response_rest(rest_status_url) versions_statuses = status_response.model_version_status version_status = versions_statuses[0] assert len(versions_statuses) == 1 assert version_status.version == 1 assert version_status.state == ModelVersionState.AVAILABLE assert version_status.status.error_code == ErrorCode.OK assert version_status.status.error_message == _ERROR_MESSAGE[ ModelVersionState.AVAILABLE][ErrorCode.OK] ### shutil.rmtree(resnet_v1_copy_dir) resnet_v2_copy_dir = copy_model(resnet_v2, 2, dir) time.sleep(10) out_name = 'resnet_v2_50/predictions/Reshape_1' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [1, 1001]}} response = get_model_metadata_response_rest(rest_url) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata # Model status check after update status_response = get_model_status_response_rest(rest_status_url) versions_statuses = status_response.model_version_status assert len(versions_statuses) == 2 for version_status in versions_statuses: assert version_status.version in [1, 2] if version_status.version == 1: assert version_status.state == ModelVersionState.END assert version_status.status.error_code == ErrorCode.OK assert version_status.status.error_message == _ERROR_MESSAGE[ ModelVersionState.END][ErrorCode.OK] elif version_status.version == 2: assert version_status.state == ModelVersionState.AVAILABLE assert version_status.status.error_code == ErrorCode.OK assert version_status.status.error_message == _ERROR_MESSAGE[ ModelVersionState.AVAILABLE][ErrorCode.OK] ### shutil.rmtree(resnet_v2_copy_dir) time.sleep(10)
def test_update_rest_grpc(self, download_two_model_versions, resnet_2_out_model_downloader, get_test_dir, start_server_update_flow_specific, create_channel_for_update_flow_specific): resnet_v1, resnet_v2 = download_two_model_versions resnet_2_out = resnet_2_out_model_downloader dir = get_test_dir + '/saved_models/' + 'update/' stub = create_channel_for_update_flow_specific resnet_v1_copy_dir = copy_model(resnet_v1, 1, dir) resnet_2_out_copy_dir = copy_model(resnet_2_out, 4, dir) time.sleep(8) # Available versions: 1, 4 print("Getting info about resnet model") model_name = 'resnet' out_name_v1 = 'resnet_v1_50/predictions/Reshape_1' expected_input_metadata_v1 = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata_v1 = { out_name_v1: { 'dtype': 1, 'shape': [1, 1000] } } request = get_model_metadata(model_name=model_name, version=1) response = stub.GetModelMetadata(request, 10) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata_v1 == input_metadata assert expected_output_metadata_v1 == output_metadata rest_url = 'http://localhost:5563/v1/models/resnet/metadata' response_latest = get_model_metadata_response_rest(rest_url) print("response", response_latest) input_metadata_latest, output_metadata_latest = \ model_metadata_response(response=response_latest) request_v4 = get_model_metadata(model_name=model_name, version=4) response_v4 = stub.GetModelMetadata(request_v4, 10) print("response", response_v4) input_metadata_v4, output_metadata_v4 = model_metadata_response( response=response_latest) assert response_v4.model_spec.name == response_latest.model_spec.name assert input_metadata_v4 == input_metadata_latest assert output_metadata_v4 == output_metadata_latest shutil.rmtree(resnet_2_out_copy_dir) resnet_v2_copy_dir = copy_model(resnet_v2, 3, dir) time.sleep(3) # Available versions: 1, 3 request_latest = get_model_metadata(model_name=model_name) response_latest = stub.GetModelMetadata(request_latest, 10) print("response", response_latest) input_metadata_latest, output_metadata_latest = \ model_metadata_response(response=response_latest) rest_url = 'http://localhost:5563/v1/models/resnet/versions/3/metadata' response_v3 = get_model_metadata_response_rest(rest_url) print("response", response_v3) input_metadata_v3, output_metadata_v3 = model_metadata_response( response=response_v3) assert response_v3.model_spec.name == response_latest.model_spec.name assert input_metadata_v3 == input_metadata_latest assert output_metadata_v3 == output_metadata_latest # Available versions: 1, 3, 4 resnet_2_out_copy_dir = copy_model(resnet_2_out, 4, dir) time.sleep(3) rest_url = 'http://localhost:5563/v1/models/resnet/versions/1/metadata' response_v1 = get_model_metadata_response_rest(rest_url) input_metadata_v1, output_metadata_v1 = model_metadata_response( response=response_v1) assert model_name == response.model_spec.name assert expected_input_metadata_v1 == input_metadata_v1 assert expected_output_metadata_v1 == output_metadata_v1 out_name_v3 = 'resnet_v2_50/predictions/Reshape_1' expected_input_metadata_v3 = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata_v3 = { out_name_v3: { 'dtype': 1, 'shape': [1, 1001] } } request_v3 = get_model_metadata(model_name=model_name, version=3) response_v3 = stub.GetModelMetadata(request_v3, 10) input_metadata_v3, output_metadata_v3 = model_metadata_response( response=response_v3) assert model_name == response.model_spec.name assert expected_input_metadata_v3 == input_metadata_v3 assert expected_output_metadata_v3 == output_metadata_v3 expected_input_metadata_v4 = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata_v4 = { 'res5c_branch2c1': { 'dtype': 1, 'shape': [1, 2048, 7, 7] }, 'res5c_branch2c2': { 'dtype': 1, 'shape': [1, 2048, 7, 7] } } rest_url = 'http://localhost:5563/v1/models/resnet/versions/4/metadata' response_v4 = get_model_metadata_response_rest(rest_url) input_metadata_v4, output_metadata_v4 = model_metadata_response( response=response_v4) assert model_name == response_v4.model_spec.name assert expected_input_metadata_v4 == input_metadata_v4 assert expected_output_metadata_v4 == output_metadata_v4 shutil.rmtree(resnet_v2_copy_dir) shutil.rmtree(resnet_v1_copy_dir) shutil.rmtree(resnet_2_out_copy_dir)
def test_get_model_metadata_rest(self, download_two_models, start_server_multi_model): """ <b>Description</b> Execute inference request using REST API interface hosting multiple models <b>input data</b> - directory with 2 models in IR format - docker image <b>fixtures used</b> - model downloader - input data downloader - service launching <b>Expected results</b> - response contains proper response about model metadata for both models set in config file: model resnet_v1_50, pnasnet_large - both served models handles appropriate input formats """ print("Downloaded model files:", download_two_models) print("Getting info about resnet model") model_name = 'resnet_V1_50' out_name = 'resnet_v1_50/predictions/Reshape_1' expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [1, 3, 224, 224] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [1, 1000]}} rest_url = 'http://localhost:5561/v1/models/resnet_V1_50/metadata' response = get_model_metadata_response_rest(rest_url) input_metadata, output_metadata = model_metadata_response( response=response) print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata model_name = 'pnasnet_large' out_name = 'final_layer/predictions' rest_url = 'http://localhost:5561/v1/models/pnasnet_large/metadata' response = get_model_metadata_response_rest(rest_url) input_metadata, output_metadata = model_metadata_response( response=response) expected_input_metadata = { 'input': { 'dtype': 1, 'shape': [4, 3, 331, 331] } } expected_output_metadata = {out_name: {'dtype': 1, 'shape': [4, 1001]}} print(output_metadata) assert model_name == response.model_spec.name assert expected_input_metadata == input_metadata assert expected_output_metadata == output_metadata