", "" ) markdown_out = markdown_out.replace("
", "") for color in colors: markdown_out = markdown_out.replace("[COLOR]", str(desaturate(tuple(color))), 1) markdown_out = f""" {markdown_out} """ markdown_out = markdown_default + "" + markdown_out return markdown_out def show_mask_pred(image, masks, crop_range=(0, 1024, 0, 1024)): print(crop_range) selected_colors = [] colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (255, 0, 255), (0, 255, 255), (128, 128, 255), [255, 192, 203], # Pink [165, 42, 42], # Brown [255, 165, 0], # Orange [128, 0, 128], # Purple [0, 0, 128], # Navy [128, 0, 0], # Maroon [128, 128, 0], # Olive [70, 130, 180], # Steel Blue [173, 216, 230], # Light Blue [255, 192, 0], # Gold [255, 165, 165], # Light Salmon [255, 20, 147], # Deep Pink ] masks = F.interpolate(masks, size=image.size, mode='bilinear', align_corners=False) masks = masks.sigmoid() > 0.5 masks = masks.to(torch.uint8).cpu().numpy()[:, 0] _mask_image = np.zeros((masks.shape[1], masks.shape[2], 3), dtype=np.uint8) for i, mask in enumerate(masks): color = colors[i % len(colors)] selected_colors.append(color) _mask_image[:, :, 0] = _mask_image[:, :, 0] + mask.astype(np.uint8) * color[0] _mask_image[:, :, 1] = _mask_image[:, :, 1] + mask.astype(np.uint8) * color[1] _mask_image[:, :, 2] = _mask_image[:, :, 2] + mask.astype(np.uint8) * color[2] image = np.array(image) image = image * 0.5 + _mask_image * 0.5 image = image.astype(np.uint8) image = image[crop_range[2]: crop_range[3], crop_range[0]: crop_range[1], :] return image, selected_colors def parse_visual_prompts(points): ret = {'points': [], 'boxes': []} for item in points: if item[2] == 1.0: ret['points'].append([item[0], item[1]]) elif item[2] == 2.0 or item[2] == 3.0: ret['boxes'].append([item[0], item[1], item[3], item[4]]) else: raise NotImplementedError return ret