현재 제공되고 있는 모델들은 배치 사이즈 1로만 컴파일되어 있습니다. 따라서 다른 배치 사이즈를 원하신다면 새롭게 컴파일이 필요합니다. 이에 대한 자세한 방법은 컴파일 및 최적화 문서를 참조해주시기 바랍니다.
아래에는 제가 작성한 yolo pose 4배치 추론 코드 예시를 첨부해 드립니다. 참고로, yolo pose 모델을 컴파일하는 데에는 약 30분 정도의 시간이 소요될 수 있으니, 이 점 양해 부탁드립니다.
또한 배치 사이즈가 클수록 최적은 아닐 수 있으니 다양한 실험을 통해 성능을 확인해보시기를 추천드립니다.
감사합니다.
from copy import deepcopy
from time import perf_counter
import numpy as np
import onnx
from furiosa.models import vision
from furiosa.quantizer import ModelEditor, TensorType, get_pure_input_names, quantize
from furiosa.runtime.sync import create_runner
model = vision.YOLOv7w6Pose()
f32_onnx_model = onnx.load_from_string(model.origin)
model_wo_input_quantize = deepcopy(f32_onnx_model)
editor = ModelEditor(model_wo_input_quantize)
for input_name in get_pure_input_names(model_wo_input_quantize):
editor.convert_input_type(input_name, TensorType.UINT8)
quantized_onnx_wo_input_quantize = quantize(model_wo_input_quantize, model.tensor_name_to_range)
with create_runner(
quantized_onnx_wo_input_quantize,
batch_size=4,
compiler_config={"lower_tabulated_dequantize": True},
) as runner:
input_tensor_desc = runner.model.inputs()
runner.model.print_summary()
fake_input = [
np.random.randint(256, size=desc.shape, dtype=desc.dtype.numpy)
for desc in input_tensor_desc
]
starting_time = perf_counter()
for _ in range(100):
runner.run(fake_input)
print("Average inference time:", (perf_counter() - starting_time) / 100, "s")