wangjin2000 commited on
Commit
a9fc615
·
verified ·
1 Parent(s): 548271e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -48,19 +48,19 @@ 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
- img0 = letterbox(image, 640, stride=32, auto=True)[0] # Resize and pad to 640x640
55
  img = letterbox(img0, 640, stride=32, auto=True)[0] # Resize and pad to 640x640
56
- #print("in preprocess:",img.shape)
57
- #img = img.transpose(2, 0, 1)[::-1] # Convert BGR to RGB, to 3x416x416
58
  img = np.ascontiguousarray(img)
59
  img = torch.from_numpy(img).to(device)
60
  img = img.float() # uint8 to fp16/32
61
  img /= 255.0 # 0 - 255 to 0.0 - 1.0
62
  if img.ndimension() == 3:
63
- img = img.transpose(2, 0, 1)[::-1] # Convert BGR to RGB,
64
  img = img.unsqueeze(0)
65
  return img, img0
66
 
@@ -113,7 +113,7 @@ def show_preds_image(filepath):
113
  img0 = cv2.imread(filepath)
114
  img_with_boxes = draw_bounding_boxes(img0, results)
115
  return cv2.cvtColor(img_with_boxes, cv2.COLOR_BGR2RGB)
116
- '''
117
  # Define Gradio components
118
  input_component = gr.components.Image(type="filepath", label="Input Image")
119
  output_component = gr.components.Image(type="numpy", label="Output Image")
@@ -219,4 +219,5 @@ def build_interface():
219
 
220
  if __name__ == '__main__':
221
  demo = build_interface()
222
- demo.launch()
 
 
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
+ #img0 = letterbox(image, 640, stride=32, auto=True)[0] # Resize and pad to 640x640
55
  img = letterbox(img0, 640, stride=32, auto=True)[0] # Resize and pad to 640x640
56
+ print("in preprocess:",img.shape)
57
+ img = img.transpose(2, 0, 1)[::-1] # Convert BGR to RGB, to 3x416x416
58
  img = np.ascontiguousarray(img)
59
  img = torch.from_numpy(img).to(device)
60
  img = img.float() # uint8 to fp16/32
61
  img /= 255.0 # 0 - 255 to 0.0 - 1.0
62
  if img.ndimension() == 3:
63
+ #img = img.transpose(2, 0, 1)[::-1] # Convert BGR to RGB,
64
  img = img.unsqueeze(0)
65
  return img, img0
66
 
 
113
  img0 = cv2.imread(filepath)
114
  img_with_boxes = draw_bounding_boxes(img0, results)
115
  return cv2.cvtColor(img_with_boxes, cv2.COLOR_BGR2RGB)
116
+
117
  # Define Gradio components
118
  input_component = gr.components.Image(type="filepath", label="Input Image")
119
  output_component = gr.components.Image(type="numpy", label="Output Image")
 
219
 
220
  if __name__ == '__main__':
221
  demo = build_interface()
222
+ demo.launch
223
+ '''