wangjin2000 commited on
Commit
b57633e
·
verified ·
1 Parent(s): c772933

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -18,7 +18,7 @@ from yolov5.models.experimental import attempt_load
18
  from yolov5.utils.general import non_max_suppression
19
  from yolov5.utils.augmentations import letterbox
20
 
21
- '''
22
  # Example URLs for downloading images
23
  file_urls = [
24
  "https://www.dropbox.com/scl/fi/n3bs5xnl2kanqmwv483k3/1_jpg.rf.4a59a63d0a7339d280dd18ef3c2e675a.jpg?rlkey=4n9dnls1byb4wm54ycxzx3ovi&st=ue5xv8yx&dl=0",
@@ -40,7 +40,7 @@ def download_file(url, save_name):
40
  # Download images
41
  for i, url in enumerate(file_urls):
42
  download_file(url, f"image_{i}.jpg")
43
- '''
44
 
45
  # Load YOLOv5 model (placeholder)
46
  model_path = "best.pt" # Path to your YOLOv5 model
@@ -48,11 +48,11 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # Use GPU
48
  model = attempt_load(model_path, device=device) # Placeholder for model loading
49
  model.eval() # Set the model to evaluation mode
50
 
51
- #def preprocess_image(image_path):
52
- def preprocess_image(image):
53
- #img0 = cv2.imread(image_path)
54
- print("in preprocess-0 image.shape:",image.shape)
55
- img0 = letterbox(image, 640, stride=32, auto=True)[0] # Resize and pad to 640x640
56
  img = letterbox(img0, 640, stride=32, auto=True)[0] # Resize and pad to 640x640
57
  print("in preprocess-1 img.shape:",img.shape)
58
  img = img.transpose(2, 0, 1)[::-1] # Convert BGR to RGB, to 3x416x416
@@ -63,6 +63,8 @@ def preprocess_image(image):
63
  if img.ndimension() == 3:
64
  #img = img.transpose(2, 0, 1)[::-1] # Convert BGR to RGB,
65
  img = img.unsqueeze(0)
 
 
66
  return img, img0
67
 
68
  def infer(model, img):
 
18
  from yolov5.utils.general import non_max_suppression
19
  from yolov5.utils.augmentations import letterbox
20
 
21
+ #'''
22
  # Example URLs for downloading images
23
  file_urls = [
24
  "https://www.dropbox.com/scl/fi/n3bs5xnl2kanqmwv483k3/1_jpg.rf.4a59a63d0a7339d280dd18ef3c2e675a.jpg?rlkey=4n9dnls1byb4wm54ycxzx3ovi&st=ue5xv8yx&dl=0",
 
40
  # Download images
41
  for i, url in enumerate(file_urls):
42
  download_file(url, f"image_{i}.jpg")
43
+
44
 
45
  # Load YOLOv5 model (placeholder)
46
  model_path = "best.pt" # Path to your YOLOv5 model
 
48
  model = attempt_load(model_path, device=device) # Placeholder for model loading
49
  model.eval() # Set the model to evaluation mode
50
 
51
+ def preprocess_image(image_path):
52
+ #def preprocess_image(image):
53
+ img0 = cv2.imread(image_path)
54
+ print("in preprocess-0 img0.shape:",img0.shape)
55
+ #img0 = letterbox(image, 640, stride=32, auto=True)[0] # Resize and pad to 640x640
56
  img = letterbox(img0, 640, stride=32, auto=True)[0] # Resize and pad to 640x640
57
  print("in preprocess-1 img.shape:",img.shape)
58
  img = img.transpose(2, 0, 1)[::-1] # Convert BGR to RGB, to 3x416x416
 
63
  if img.ndimension() == 3:
64
  #img = img.transpose(2, 0, 1)[::-1] # Convert BGR to RGB,
65
  img = img.unsqueeze(0)
66
+ print("in preprocess-2 img.shape:",img.shape)
67
+
68
  return img, img0
69
 
70
  def infer(model, img):