Skip to content

Commit

Permalink
make sure nz model runs too
Browse files Browse the repository at this point in the history
  • Loading branch information
PetervanLunteren authored Apr 23, 2024
1 parent ea546e0 commit 91033c9
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
import torch
from PIL import ImageOps

# make sure windows trained models work on unix too
import pathlib
import platform
plt = platform.system()
if plt != 'Windows': pathlib.WindowsPath = pathlib.PosixPath

# load model
animal_model = YOLO(cls_model_fpath)

Expand Down Expand Up @@ -67,6 +73,7 @@ def get_crop(img, bbox_norm): # created by Dan Morris
box_w = int(bbox_norm[2] * img_w)
box_h = int(bbox_norm[3] * img_h)
box_size = max(box_w, box_h)
box_size = pad_crop(box_size)
xmin = max(0, min(
xmin - int((box_size - box_w) / 2),
img_w - box_w))
Expand All @@ -81,6 +88,20 @@ def get_crop(img, bbox_norm): # created by Dan Morris
crop = ImageOps.pad(crop, size=(box_size, box_size), color=0)
return crop

# make sure small animals are not overly enlarged
def pad_crop(box_size):
input_size_network = 224
default_padding = 30
diff_size = input_size_network - box_size
if box_size >= input_size_network:
box_size = box_size + default_padding
else:
if diff_size < default_padding:
box_size = box_size + default_padding
else:
box_size = input_size_network
return box_size

#############################################
############### MODEL GENERIC ###############
#############################################
Expand Down

0 comments on commit 91033c9

Please sign in to comment.