onipot commited on
Commit
0fe9ba3
1 Parent(s): 0b403b2

handle rotation, reduce input res to 720

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- from PIL import Image,ImageDraw, ImageFont
3
  import sys
4
  import torch
5
  from util import Detection
@@ -26,10 +26,16 @@ def run_yolo(img):
26
 
27
  img_path = img
28
  img0 = Image.open(img_path).convert("RGB")
 
 
 
 
 
 
29
  draw = ImageDraw.Draw(img0)
30
 
31
  predictions = predict(age_model_ts, model, stride, names, pt, jit, onnx, engine, imgsz=[320, 320], conf_thres=0.5, iou_thres=0.45, save_conf=True,
32
- exist_ok=True, nosave=True, save_txt=False, source=img_path, project=None, name=None)
33
 
34
  detections : list[Detection] = []
35
  for k, (bboxes, img) in enumerate(predictions):
@@ -54,6 +60,7 @@ def run_yolo(img):
54
  draw.rectangle(((det.xmin, det.ymin - 10), (det.xmax, det.ymin)), fill=(255,255,255))
55
  draw.text((det.xmin, det.ymin - 10), det.class_name, fill=(0,0,0), font=roboto_font)
56
 
 
57
  return img0
58
 
59
 
 
1
  import gradio as gr
2
+ from PIL import Image,ImageDraw, ImageFont, ImageOps
3
  import sys
4
  import torch
5
  from util import Detection
 
26
 
27
  img_path = img
28
  img0 = Image.open(img_path).convert("RGB")
29
+
30
+ img0 = ImageOps.contain(img0, (720,720))
31
+ img0 = ImageOps.exif_transpose(img0)
32
+
33
+ img0.save("img.jpg")
34
+
35
  draw = ImageDraw.Draw(img0)
36
 
37
  predictions = predict(age_model_ts, model, stride, names, pt, jit, onnx, engine, imgsz=[320, 320], conf_thres=0.5, iou_thres=0.45, save_conf=True,
38
+ exist_ok=True, nosave=True, save_txt=False, source="img.jpg", project=None, name=None)
39
 
40
  detections : list[Detection] = []
41
  for k, (bboxes, img) in enumerate(predictions):
 
60
  draw.rectangle(((det.xmin, det.ymin - 10), (det.xmax, det.ymin)), fill=(255,255,255))
61
  draw.text((det.xmin, det.ymin - 10), det.class_name, fill=(0,0,0), font=roboto_font)
62
 
63
+ os.remove("img.jpg")
64
  return img0
65
 
66