MCPcopy Create free account
hub / github.com/chenfei-wu/TaskMatrix / inference_all

Method inference_all

visual_chatgpt.py:997–1024  ·  view source on GitHub ↗
(self,image_path)

Source from the content-addressed store, hash-verified

995 "or segment all the object in this image."
996 "The input to this tool should be a string, representing the image_path")
997 def inference_all(self,image_path):
998 image = cv2.imread(image_path)
999 image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
1000 masks = self.mask_generator.generate(image)
1001 plt.figure(figsize=(20,20))
1002 plt.imshow(image)
1003 if len(masks) == 0:
1004 return
1005 sorted_anns = sorted(masks, key=(lambda x: x['area']), reverse=True)
1006 ax = plt.gca()
1007 ax.set_autoscale_on(False)
1008 polygons = []
1009 color = []
1010 for ann in sorted_anns:
1011 m = ann['segmentation']
1012 img = np.ones((m.shape[0], m.shape[1], 3))
1013 color_mask = np.random.random((1, 3)).tolist()[0]
1014 for i in range(3):
1015 img[:,:,i] = color_mask[i]
1016 ax.imshow(np.dstack((img, m)))
1017
1018 updated_image_path = get_new_image_name(image_path, func_name="segment-image")
1019 plt.axis('off')
1020 plt.savefig(
1021 updated_image_path,
1022 bbox_inches="tight", dpi=300, pad_inches=0.0
1023 )
1024 return updated_image_path
1025
1026class Text2Box:
1027 def __init__(self, device):

Callers

nothing calls this directly

Calls 1

get_new_image_nameFunction · 0.85

Tested by

no test coverage detected