Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -126,20 +126,6 @@ def process_image(image, task_prompt, text_input=None, model_id='dwb2023/florenc
|
|
126 |
else:
|
127 |
return "", None # Return empty string and None for unknown task prompts
|
128 |
|
129 |
-
|
130 |
-
def process_segmentation(image_path, annotation_file_path):
|
131 |
-
coco = COCO(annotation_file_path)
|
132 |
-
img_id = list(coco.imgs.keys())[0]
|
133 |
-
img_info = coco.loadImgs(img_id)[0]
|
134 |
-
ann_ids = coco.getAnnIds(imgIds=img_id)
|
135 |
-
anns = coco.loadAnns(ann_ids)
|
136 |
-
|
137 |
-
image = Image.open(image_path)
|
138 |
-
for ann in anns:
|
139 |
-
if 'segmentation' in ann and ann['segmentation']:
|
140 |
-
image = draw_polygons(image, {'polygons': ann['segmentation'], 'labels': [coco.loadCats(ann['category_id'])[0]['name']]})
|
141 |
-
return image
|
142 |
-
|
143 |
single_task_list =[
|
144 |
'Object Detection'
|
145 |
]
|
@@ -147,10 +133,28 @@ single_task_list =[
|
|
147 |
# Define the path to the example images and annotations file
|
148 |
example_image_dir = 'examples/bccd-test/'
|
149 |
annotations_file_path = os.path.join(example_image_dir, '_annotations.coco.json')
|
150 |
-
|
151 |
-
# Get the list of example image files
|
152 |
example_images = [f for f in os.listdir(example_image_dir) if f.endswith('.jpg')]
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
with gr.Blocks(theme="sudeepshouche/minimalist") as demo:
|
155 |
gr.Markdown("## 🧬OmniScience - building teams of fine tuned VLM models for diagnosis and detection 🔧")
|
156 |
gr.Markdown("- 🔬Florence-2 Model Proof of Concept, focusing on Object Detection <OD> tasks.")
|
@@ -159,7 +163,6 @@ with gr.Blocks(theme="sudeepshouche/minimalist") as demo:
|
|
159 |
gr.Markdown("BCCD Datasets on Hugging Face:")
|
160 |
gr.Markdown("- [🌺 Florence 2](https://huggingface.co/datasets/dwb2023/roboflow100-bccd-florence2/viewer/default/test?q=BloodImage_00038_jpg.rf.1b0ce1635e11b3b49302de527c86bb02.jpg), [💎 PaliGemma](https://huggingface.co/datasets/dwb2023/roboflow-bccd-paligemma/viewer/default/test?q=BloodImage_00038_jpg.rf.1b0ce1635e11b3b49302de527c86bb02.jpg)")
|
161 |
|
162 |
-
|
163 |
with gr.Tab(label="Florence-2 Object Detection"):
|
164 |
with gr.Row():
|
165 |
with gr.Column():
|
|
|
126 |
else:
|
127 |
return "", None # Return empty string and None for unknown task prompts
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
single_task_list =[
|
130 |
'Object Detection'
|
131 |
]
|
|
|
133 |
# Define the path to the example images and annotations file
|
134 |
example_image_dir = 'examples/bccd-test/'
|
135 |
annotations_file_path = os.path.join(example_image_dir, '_annotations.coco.json')
|
|
|
|
|
136 |
example_images = [f for f in os.listdir(example_image_dir) if f.endswith('.jpg')]
|
137 |
|
138 |
+
cfg = get_cfg()
|
139 |
+
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
|
140 |
+
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
|
141 |
+
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
|
142 |
+
cfg.MODEL.DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
143 |
+
predictor = DefaultPredictor(cfg)
|
144 |
+
|
145 |
+
def process_image(image_name):
|
146 |
+
image_path = os.path.join(example_image_dir, image_name)
|
147 |
+
image = cv2.imread(image_path)
|
148 |
+
outputs = predictor(image)
|
149 |
+
v = Visualizer(image[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
|
150 |
+
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
|
151 |
+
plt.figure(figsize=(14, 10))
|
152 |
+
plt.imshow(out.get_image()[:, :, ::-1])
|
153 |
+
plt.axis('off')
|
154 |
+
plt.show()
|
155 |
+
return out.get_image()[:, :, ::-1]
|
156 |
+
|
157 |
+
|
158 |
with gr.Blocks(theme="sudeepshouche/minimalist") as demo:
|
159 |
gr.Markdown("## 🧬OmniScience - building teams of fine tuned VLM models for diagnosis and detection 🔧")
|
160 |
gr.Markdown("- 🔬Florence-2 Model Proof of Concept, focusing on Object Detection <OD> tasks.")
|
|
|
163 |
gr.Markdown("BCCD Datasets on Hugging Face:")
|
164 |
gr.Markdown("- [🌺 Florence 2](https://huggingface.co/datasets/dwb2023/roboflow100-bccd-florence2/viewer/default/test?q=BloodImage_00038_jpg.rf.1b0ce1635e11b3b49302de527c86bb02.jpg), [💎 PaliGemma](https://huggingface.co/datasets/dwb2023/roboflow-bccd-paligemma/viewer/default/test?q=BloodImage_00038_jpg.rf.1b0ce1635e11b3b49302de527c86bb02.jpg)")
|
165 |
|
|
|
166 |
with gr.Tab(label="Florence-2 Object Detection"):
|
167 |
with gr.Row():
|
168 |
with gr.Column():
|