Inferring Yolo_v3.trt model in python

In your code, the ratio can be min(self.model_w/float(img_w), self.model_h/float(img_h))
Then,

new_w = int(round(img_w * ratio))
new_h = int(round(img_h*ratio))

Please try to resize the image via PIL instead of cv.

im = img.resize((new_w, new_h), Image.ANTIALIAS)

inf_img = Image.new(‘RGB’,(self.model_w, self.model_h))
inf_img.paste(im, (0, 0))