Spaces:
Sleeping
Sleeping
File size: 733 Bytes
f0e6dd6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import onnx
import onnxruntime as ort
import numpy as np
VIT_MODEL_DSV3_REPO = "SmilingWolf/wd-vit-tagger-v3"
def preprocess_image(img):
bgr_img = np.array(img)[:, :, ::-1].copy()
size = max(bgr_img.shape[0:2])
pad_x = size - bgr_img.shape[1]
pad_y = size - bgr_img.shape[0]
pad_l = pad_x // 2
pad_t = pad_y // 2
#add paddings to squaring image
np.pad(bgr_img, ((pad_t, pad_y - pad_t), (pad_l, pad_x - pad_l), (0, 0)), mode="constant", constant_values=255)
#adaptive resize
interp = cv2.INTER_AREA if size > IMAGE_SIZE else cv2.INTER_LANCZOS4
bgr_img = cv2.resize(bgr_img, (IMAGE_SIZE, IMAGE_SIZE), interpolation=interp)
bgr_img = bgr_img.astype(np.float32) |