コード例 #1
0
def create_onnx_modelconfig(
        models_dir, model_version, max_batch, dtype,
        input_shapes, input_model_shapes, output_shapes, output_model_shapes):

    assert len(input_shapes) == len(input_model_shapes)
    assert len(output_shapes) == len(output_model_shapes)
    assert len(input_shapes) == len(output_shapes)
    if not tu.validate_for_onnx_model(dtype, dtype, dtype,
                                      input_shapes[0], input_shapes[0], input_shapes[0]):
        return

    io_cnt = len(input_shapes)

    # Use a different model name for the non-batching variant
    model_name = tu.get_zero_model_name("onnx_nobatch" if max_batch == 0 else "onnx",
                                   io_cnt, dtype)
    config_dir = models_dir + "/" + model_name

    config = emu.create_general_modelconfig(model_name, "onnxruntime_onnx", max_batch,
            emu.repeat(dtype, io_cnt), input_shapes, input_model_shapes,
            emu.repeat(dtype, io_cnt), output_shapes, output_model_shapes,
            emu.repeat(None, io_cnt), force_tensor_number_suffix=True)

    try:
        os.makedirs(config_dir)
    except OSError as ex:
        pass # ignore existing dir

    with open(config_dir + "/config.pbtxt", "w") as cfile:
        cfile.write(config)
コード例 #2
0
def create_onnx_modelconfig(models_dir, model_version, max_batch, dtype,
                            input_shapes, input_model_shapes, output_shapes,
                            output_model_shapes):

    assert len(input_shapes) == len(input_model_shapes)
    assert len(output_shapes) == len(output_model_shapes)
    assert len(input_shapes) == len(output_shapes)
    if not tu.validate_for_onnx_model(dtype, dtype, dtype, input_shapes[0],
                                      input_shapes[0], input_shapes[0]):
        return

    io_cnt = len(input_shapes)

    # Use a different model name for the non-batching variant
    model_name = tu.get_zero_model_name(
        "onnx_nobatch" if max_batch == 0 else "onnx", io_cnt, dtype)
    config_dir = models_dir + "/" + model_name

    # Must make sure all Onnx models will be loaded to the same GPU if they are
    # run on GPU. This is due to the current limitation of Onnx Runtime
    # https://github.com/microsoft/onnxruntime/issues/1034
    instance_group_string = '''
instance_group [
  {
    count: 1
    kind: KIND_GPU
    gpus: [ 0 ]
  }
]
'''

    config = emu.create_general_modelconfig(
        model_name,
        "onnxruntime_onnx",
        max_batch,
        emu.repeat(dtype, io_cnt),
        input_shapes,
        input_model_shapes,
        emu.repeat(dtype, io_cnt),
        output_shapes,
        output_model_shapes,
        emu.repeat(None, io_cnt),
        force_tensor_number_suffix=True,
        instance_group_str=instance_group_string)

    try:
        os.makedirs(config_dir)
    except OSError as ex:
        pass  # ignore existing dir

    with open(config_dir + "/config.pbtxt", "w") as cfile:
        cfile.write(config)
コード例 #3
0
def create_onnx_modelconfig(
        models_dir, max_batch, model_version,
        input_shape, output0_shape, output1_shape,
        input_dtype, output0_dtype, output1_dtype,
        output0_label_cnt, version_policy):

    if not tu.validate_for_onnx_model(input_dtype, output0_dtype, output1_dtype,
                                     input_shape, output0_shape, output1_shape):
        return

    # Use a different model name for the non-batching variant
    model_name = tu.get_model_name("onnx_nobatch" if max_batch == 0 else "onnx",
                                   input_dtype, output0_dtype, output1_dtype)
    config_dir = models_dir + "/" + model_name
    
    # Must make sure all Onnx models will be loaded to the same GPU if they are
    # run on GPU. This is due to the current limitation of Onnx Runtime
    # https://github.com/microsoft/onnxruntime/issues/1034
    instance_group_string = '''
instance_group [
  {
    count: 1
    kind: KIND_GPU
    gpus: [ 0 ]
  }
]
'''
    # [TODO] move create_general_modelconfig() out of emu as it is general
    # enough for all backends to use
    config = emu.create_general_modelconfig(model_name, "onnxruntime_onnx", max_batch,
            emu.repeat(input_dtype, 2), emu.repeat(input_shape, 2), emu.repeat(None, 2),
            [output0_dtype, output1_dtype], [output0_shape, output1_shape], emu.repeat(None, 2),
            ["output0_labels.txt", None],
            version_policy=version_policy, force_tensor_number_suffix=True,
            instance_group_str=instance_group_string)

    try:
        os.makedirs(config_dir)
    except OSError as ex:
        pass # ignore existing dir

    with open(config_dir + "/config.pbtxt", "w") as cfile:
        cfile.write(config)

    with open(config_dir + "/output0_labels.txt", "w") as lfile:
        for l in range(output0_label_cnt):
            lfile.write("label" + str(l) + "\n")