hlydecker commited on
Commit
4a62603
·
1 Parent(s): ff697ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -36,10 +36,14 @@ def segment_buildings(im):
36
  # Convert PIL Image to NumPy array
37
  im = np.array(im)
38
 
 
 
 
 
39
  outputs = predictor(im)
40
 
41
  # We can use `Visualizer` to draw the predictions on the image.
42
- v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
43
  out_im = v.draw_instance_predictions(outputs["instances"].to("cpu")).get_image()
44
 
45
  # Convert the output image back to PIL Image
 
36
  # Convert PIL Image to NumPy array
37
  im = np.array(im)
38
 
39
+ # Ensure that the image has shape H x W x C (height x width x channels)
40
+ if im.shape[-1] == 4: # If it has 4 channels (RGBA), remove the alpha channel
41
+ im = im[:, :, :3]
42
+
43
  outputs = predictor(im)
44
 
45
  # We can use `Visualizer` to draw the predictions on the image.
46
+ v = Visualizer(im, MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
47
  out_im = v.draw_instance_predictions(outputs["instances"].to("cpu")).get_image()
48
 
49
  # Convert the output image back to PIL Image