update the codebase poc ver1
This commit is contained in:
@@ -28,6 +28,17 @@ def preprocess_224(img: Image.Image) -> np.ndarray:
|
||||
arr = np.expand_dims(arr, axis=0) # Add batch dim -> NCHW
|
||||
return arr
|
||||
|
||||
def preprocess_512(img: Image.Image) -> np.ndarray:
|
||||
"""Preprocesses image to NCHW FP32 [1, 3, 512, 512] matching ResNet50 input requirements"""
|
||||
img_resized = img.resize((512, 512), Image.Resampling.BILINEAR)
|
||||
arr = np.asarray(img_resized).astype(np.float32) / 255.0
|
||||
mean = np.array([0.485, 0.456, 0.406], dtype=np.float32)
|
||||
std = np.array([0.229, 0.224, 0.225], dtype=np.float32)
|
||||
arr = (arr - mean) / std
|
||||
arr = arr.transpose(2, 0, 1) # HWC -> CHW
|
||||
arr = np.expand_dims(arr, axis=0) # Add batch dim -> NCHW
|
||||
return arr
|
||||
|
||||
def softmax(x: np.ndarray) -> np.ndarray:
|
||||
e = np.exp(x - np.max(x))
|
||||
return e / np.sum(e)
|
||||
|
||||
Reference in New Issue
Block a user