Repository: onnx/onnx
File: onnx/utils.py (Python)

Code before:
        check_model (bool): Whether to run model checker on the original model and the extracted model.
        infer_shapes (bool): Whether to infer the shapes of the original model.
    """
    if not os.path.exists(input_path):
        raise ValueError(f"Invalid input model path: {input_path}")
    if not output_path:
        raise ValueError("Output model path shall not be empty!")
    if not output_names:
        raise ValueError("Output tensor names shall not be empty!")

    if check_model:
        onnx.checker.check_model(input_path)

    if infer_shapes and os.path.getsize(input_path) > MAXIMUM_PROTOBUF:
        onnx.shape_inference.infer_shapes_path(input_path, output_path)
        model = onnx.load(output_path)
    else:
        model = onnx.load(input_path)
        if infer_shapes:
            model = onnx.shape_inference.infer_shapes(model)

    e = Extractor(model)
    extracted = e.extract_model(input_names, output_names)

    if extracted.ByteSize() > MAXIMUM_PROTOBUF:
        location = os.path.basename(output_path) + "_data"
        onnx.save(extracted, output_path, save_as_external_data=True, location=location)
    else:
        onnx.save(extracted, output_path)

    if check_model:
        onnx.checker.check_model(output_path)


def _tar_members_filter(
    tar: tarfile.TarFile, base: str | os.PathLike
) -> list[tarfile.TarInfo]:
    """Check that the content of ``tar`` will be extracted safely

    Args:
        tar: The tarball file
        base: The directory where the tarball will be extracted

    Returns:
        list of tarball members
    """
    result = []
    for member in tar:
        member_path = os.path.join(base, member.name)
        abs_base = os.path.abspath(base)
        abs_member = os.path.abspath(member_path)

Review comment (suggestion):
```suggestion
        location = os.path.basename(output_path) + ".data"
```

consider a .data extension? When the model extension is not onnx, for example json, the original will produce json_data etc which is a little arbitrary 

Code after:
        output_names (list of string): The names of the output tensors that to be extracted.
        check_model (bool): Whether to run model checker on the original model and the extracted model.
        infer_shapes (bool): Whether to infer the shapes of the original model.
    """
    if not os.path.exists(input_path):
        raise ValueError(f"Invalid input model path: {input_path}")
    if not output_path:
        raise ValueError("Output model path shall not be empty!")
    if not output_names:
        raise ValueError("Output tensor names shall not be empty!")

    if check_model:
        onnx.checker.check_model(input_path)

    if infer_shapes and os.path.getsize(input_path) > onnx.checker.MAXIMUM_PROTOBUF:
        onnx.shape_inference.infer_shapes_path(input_path, output_path)
        model = onnx.load(output_path)
    else:
        model = onnx.load(input_path)
        if infer_shapes:
            model = onnx.shape_inference.infer_shapes(model)

    e = Extractor(model)
    extracted = e.extract_model(input_names, output_names)

    if extracted.ByteSize() > onnx.checker.MAXIMUM_PROTOBUF:
        location = os.path.basename(output_path) + ".data"
        onnx.save(extracted, output_path, save_as_external_data=True, location=location)
    else:
        onnx.save(extracted, output_path)

    if check_model:
        onnx.checker.check_model(output_path)


def _tar_members_filter(
    tar: tarfile.TarFile, base: str | os.PathLike
) -> list[tarfile.TarInfo]:
    """Check that the content of ``tar`` will be extracted safely

    Args:
        tar: The tarball file
        base: The directory where the tarball will be extracted

    Returns:
        list of tarball members
    """
    result = []
    for member in tar:
        member_path = os.path.join(base, member.name)
        abs_base = os.path.abspath(base)