Jazz1508 commited on
Commit
fe4e370
·
verified ·
1 Parent(s): 0c11167

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -33,7 +33,7 @@ transform = Compose([
33
  ToTensorV2()
34
  ])
35
 
36
- def predict(image, threshold=0.5):
37
  """Process the image and detect camouflage objects."""
38
  img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
39
  augmented = transform(image=img)
@@ -42,8 +42,8 @@ def predict(image, threshold=0.5):
42
  with torch.no_grad():
43
  output = torch.sigmoid(model(img_tensor))
44
 
45
- # Apply threshold
46
- mask = (output.squeeze().cpu().numpy() > threshold).astype(np.uint8) * 255
47
 
48
  # Resize mask to original image size
49
  mask_resized = cv2.resize(mask, (image.shape[1], image.shape[0]))
@@ -69,14 +69,13 @@ with gr.Blocks(css=custom_css, theme="soft") as app:
69
  with gr.Row():
70
  with gr.Column():
71
  image_input = gr.Image(type="numpy", label="Upload Image")
72
- threshold_slider = gr.Slider(0.1, 1.0, value=0.5, label="Detection Threshold", interactive=True)
73
  submit_btn = gr.Button("🔍 Detect")
74
 
75
  with gr.Column():
76
  output_overlay = gr.Image(type="numpy", label="Detected Camouflage (Overlay)")
77
  output_mask = gr.Image(type="numpy", label="Segmentation Mask")
78
 
79
- submit_btn.click(predict, inputs=[image_input, threshold_slider], outputs=[output_overlay, output_mask])
80
 
81
  gr.HTML('<div id="footer-text">Made with ❤️ by Jaskaranjeet Singh</div>')
82
 
 
33
  ToTensorV2()
34
  ])
35
 
36
+ def predict(image):
37
  """Process the image and detect camouflage objects."""
38
  img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
39
  augmented = transform(image=img)
 
42
  with torch.no_grad():
43
  output = torch.sigmoid(model(img_tensor))
44
 
45
+ # Convert model output to binary mask
46
+ mask = (output.squeeze().cpu().numpy() > 0.5).astype(np.uint8) * 255
47
 
48
  # Resize mask to original image size
49
  mask_resized = cv2.resize(mask, (image.shape[1], image.shape[0]))
 
69
  with gr.Row():
70
  with gr.Column():
71
  image_input = gr.Image(type="numpy", label="Upload Image")
 
72
  submit_btn = gr.Button("🔍 Detect")
73
 
74
  with gr.Column():
75
  output_overlay = gr.Image(type="numpy", label="Detected Camouflage (Overlay)")
76
  output_mask = gr.Image(type="numpy", label="Segmentation Mask")
77
 
78
+ submit_btn.click(predict, inputs=[image_input], outputs=[output_overlay, output_mask])
79
 
80
  gr.HTML('<div id="footer-text">Made with ❤️ by Jaskaranjeet Singh</div>')
81