Update 1/model.py
This commit is contained in:
parent
130edcdfcf
commit
54fc4ad91c
39
1/model.py
39
1/model.py
@ -42,6 +42,45 @@ class TritonPythonModel:
|
|||||||
|
|
||||||
return responses
|
return responses
|
||||||
|
|
||||||
|
def _get_input_value(self, request, input_name: str, default=None):
|
||||||
|
"""
|
||||||
|
Triton 추론 요청에서 특정 이름의 입력 텐서 값을 가져옵니다.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (pb_utils.InferenceRequest): Triton 추론 요청 객체.
|
||||||
|
input_name (str): 가져올 입력 텐서의 이름.
|
||||||
|
default (any, optional): 입력 텐서가 없을 경우 반환할 기본값. Defaults to None.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
any: 디코딩된 입력 텐서의 값. 텐서가 없으면 기본값을 반환합니다.
|
||||||
|
"""
|
||||||
|
tensor_value = pb_utils.get_input_tensor_by_name(request, input_name)
|
||||||
|
|
||||||
|
if tensor_value is None:
|
||||||
|
return default
|
||||||
|
|
||||||
|
return self._np_decoder(tensor_value.as_numpy()[0])
|
||||||
|
|
||||||
|
def _np_decoder(self, obj):
|
||||||
|
"""
|
||||||
|
NumPy 객체의 데이터 타입을 확인하고 Python 기본 타입으로 변환합니다.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
obj (numpy.ndarray element): 변환할 NumPy 배열의 요소.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
any: 해당 NumPy 요소에 대응하는 Python 기본 타입 (str, int, float, bool).
|
||||||
|
bytes 타입인 경우 UTF-8로 디코딩합니다.
|
||||||
|
"""
|
||||||
|
if isinstance(obj, bytes):
|
||||||
|
return obj.decode('utf-8')
|
||||||
|
if np.issubdtype(obj, np.integer):
|
||||||
|
return int(obj)
|
||||||
|
if np.issubdtype(obj, np.floating):
|
||||||
|
return round(float(obj), 3)
|
||||||
|
if isinstance(obj, np.bool_):
|
||||||
|
return bool(obj)
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
"""
|
"""
|
||||||
모델 실행이 완료된 후 Triton 서버가 종료될 때 한 번 호출되는 함수입니다.
|
모델 실행이 완료된 후 Triton 서버가 종료될 때 한 번 호출되는 함수입니다.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user