Open amin3511 opened 6 years ago
check the display_instances in visualize.py. Just set a specific color for a specific class object detected
You can get your class id in class_ids[i]
and use apre-defined color
. This takes place indisplay_instances
in visualize.py
. To note that you can give an array of colors to display_instances
function.
@fastlater ,@arthurPrvst Thanks for your guidance please say i shoude be done what exactly for this
@amin3511 , you have to know which class_id
correpond to which object. If person class has a class_id of 1, dog classe has a class_id of 2 you can display them like this :
Add this code after if show_mask
: in display_instances
function in visualize.py
line 156 :
if class_id == 1:
masked_image = apply_mask(masked_image, mask, [1, 0, 0], alpha=1)
elif class_id == 2:
masked_image = apply_mask(masked_image, mask, [0, 1, 0], alpha=1)
else
masked_image = apply_mask(masked_image, mask, [0, 0, 1], alpha=1)
It will display persons in red, dogs in green and cats in blue.
@arthurPrvst , i added this code after if show_mask:
mask = masks[:, :, i]
if show_mask:
masked_image = apply_mask(masked_image, mask, color
# Mask Polygon
if class_id == 1:
masked_image = apply_mask(masked_image, mask, [1, 0, 0], alpha=1)
elif class_id == 2:
masked_image = apply_mask(masked_image, mask, [0, 1, 0], alpha=1)
else
masked_image = apply_mask(masked_image, mask, [0, 0, 1], alpha=1)
but when i run the code i get this error Traceback (most recent call last):
File "/home/ubuntu/anaconda3/envs/MaskRCNN/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code exec(code_obj, self.user_global_ns, self.user_ns)
File "
File "/home/ubuntu/Downloads/Mask_RCNN/mrcnn/visualize.py", line 157 if class_ids == 1: ^ SyntaxError: invalid syntax
Remove first line after if show_mask
, and put all the code in the if block.
Thanks @arthurPrvst for your guidance Just another question how can i know which class_id correpond to which object?
@arthurPrvst
HI Arthur, I am using the matterport code for an use case where i am generating masks to blur personal details in images like faces, car no plate etc. The masks generated are very transparent and hence nothing gets blurred actually. I tried changing the code in visualize.py for each of the brightness and saturation values.
def random_colors(N, bright=True):
"""
Generate random colors.
To get visually distinct colors, generate them in HSV space then
convert to RGB.
"""
brightness = 1.0 if bright else 0.7
hsv = [(i / N, 1, brightness) for i in range(N)]
colors = list(map(lambda c: colorsys.hsv_to_rgb(*c), hsv))
random.shuffle(colors)
return colors
But if i change the brightness to 0 or 1 , it either becomes dark or white but the density of color donot change. How can i achieve a complete opaque color, kindly advice. Many thanks in advance.
@arthurPrvst HI Arthur, I am using the matterport code for an use case where i am generating masks to blur personal details in images like faces, car no plate etc. The masks generated are very transparent and hence nothing gets blurred actually. I tried changing the code in visualize.py for each of the brightness and saturation values. def random_colors(N, bright=True): """ Generate random colors. To get visually distinct colors, generate them in HSV space then convert to RGB. """ brightness = 1.0 if bright else 0.7 hsv = [(i / N, 1, brightness) for i in range(N)] colors = list(map(lambda c: colorsys.hsv_to_rgb(*c), hsv)) random.shuffle(colors) return colors
But if i change the brightness to 0 or 1 , it either becomes dark or white but the density of color donot change. How can i achieve a complete opaque color, kindly advice. Many thanks in advance.
Hi @padmaksha18 go to visualize.py and change your 'if show_mask:' statement in display_instances function to:
if show_mask: if class_id == 1: mask_image = apply_mask(masked_image,mask,[1,0,0],alpha=1) if class_id == 2: mask_image = apply_mask(masked_image,mask,[0,1,0],alpha=1) if class_id == 3: mask_image = apply_mask(masked_image,mask,[0,0,1],alpha=1)
class 1 will be masked as RED, class 2 will be masked as GREEN, & Class 3 will be marked as BLUE. But for Opaqueness be sure to assign '1' to alpha in "apply_mask".
Hope it solves your problem.
@arthurPrvst HI Arthur, I am using the matterport code for an use case where i am generating masks to blur personal details in images like faces, car no plate etc. The masks generated are very transparent and hence nothing gets blurred actually. I tried changing the code in visualize.py for each of the brightness and saturation values. def random_colors(N, bright=True): """ Generate random colors. To get visually distinct colors, generate them in HSV space then convert to RGB. """ brightness = 1.0 if bright else 0.7 hsv = [(i / N, 1, brightness) for i in range(N)] colors = list(map(lambda c: colorsys.hsv_to_rgb(*c), hsv)) random.shuffle(colors) return colors But if i change the brightness to 0 or 1 , it either becomes dark or white but the density of color donot change. How can i achieve a complete opaque color, kindly advice. Many thanks in advance.
Hi @padmaksha18 go to visualize.py and change your 'if show_mask:' statement in display_instances function to:
if show_mask: if class_id == 1: mask_image = apply_mask(masked_image,mask,[1,0,0],alpha=1) if class_id == 2: mask_image = apply_mask(masked_image,mask,[0,1,0],alpha=1) if class_id == 3: mask_image = apply_mask(masked_image,mask,[0,0,1],alpha=1)
class 1 will be masked as RED, class 2 will be masked as GREEN, & Class 3 will be marked as BLUE. But for Opaqueness be sure to assign '1' to alpha in "apply_mask".
Hope it solves your problem.
Hi bro,
You know how to change the score and class id in the instance.
like the score in this fig. It is white and hard to read. So i change the display_instance in line 138-147 in visulaize.py
# Label
if not captions:
class_id = class_ids[i]
score = scores[i] if scores is not None else None
label = class_names[class_id]
caption = "{} {:.3f}".format(label, score) if score else label
else:
caption = captions[i]
ax.text(x1, y1 + 8, caption,
color='b', size=110, backgroundcolor="w")
I change the color=‘w’ to 'b'. Just nothing changes.
hi everybody i used demo.ipynb and When I run the program, the image that the output shows each time with a different and random color, for example, indicates the person in the image once in blue and again in violet. I want to display the same image every time in the program, for example, a person with a constant color and the colors are not random.That is, all dogs are shown with a specific color. All cats with a color and ... Can anyone help me?