ReyaLabColumbia commited on
Commit
daa3b76
·
verified ·
1 Parent(s): c16c74c

Upload 2 files

Browse files
Files changed (2) hide show
  1. Colony_Analyzer_AI2_HF.py +2 -12
  2. app.py +1 -1
Colony_Analyzer_AI2_HF.py CHANGED
@@ -71,18 +71,8 @@ from transformers import SegformerForSemanticSegmentation, SegformerImageProcess
71
  image_processor = SegformerImageProcessor.from_pretrained("nvidia/segformer-b3-finetuned-cityscapes-1024-1024")
72
 
73
  def preprocess_image(image):
74
- # Gradio gives image in RGB as numpy array; explicitly ensure it's uint8
75
- if image.dtype != np.uint8:
76
- image = (255 * image).astype(np.uint8)
77
-
78
- # explicitly confirm 3 channels RGB
79
- if image.ndim == 2:
80
- image = np.stack([image] * 3, axis=-1) # grayscale to RGB explicitly
81
- elif image.shape[2] == 4:
82
- image = image[:, :, :3] # RGBA to RGB explicitly
83
-
84
- # Now explicitly preprocess using Hugging Face image_processor
85
- inputs = image_processor(image, return_tensors="pt")
86
  return image, inputs["pixel_values"]
87
 
88
  def postprocess_mask(logits):
 
71
  image_processor = SegformerImageProcessor.from_pretrained("nvidia/segformer-b3-finetuned-cityscapes-1024-1024")
72
 
73
  def preprocess_image(image):
74
+ image = image.convert("RGB") # Open and convert to RGB
75
+ inputs = image_processor(image, return_tensors="pt") # Preprocess for model
 
 
 
 
 
 
 
 
 
 
76
  return image, inputs["pixel_values"]
77
 
78
  def postprocess_mask(logits):
app.py CHANGED
@@ -21,7 +21,7 @@ def analyze_image(image, min_size, circularity):
21
  iface = gr.Interface(
22
  fn=analyze_image,
23
  inputs=[
24
- gr.Image(type="numpy", label="Upload Image"),
25
  gr.Number(label="Minimum Colony Size (pixels)", value=1000),
26
  gr.Number(label="Minimum Circularity", value=0.25)
27
  ],
 
21
  iface = gr.Interface(
22
  fn=analyze_image,
23
  inputs=[
24
+ gr.Image(type="pil", label="Upload Image"),
25
  gr.Number(label="Minimum Colony Size (pixels)", value=1000),
26
  gr.Number(label="Minimum Circularity", value=0.25)
27
  ],