bendangnuksung / mrcnn_serving_ready

🛠 Mask R-CNN Keras to Tensorflow and TFX models + Serving models using TFX GRPC & RESTAPI
https://github.com/matterport/Mask_RCNN
MIT License
103 stars 35 forks source link

how to display masked result image? #11

Open angyee opened 5 years ago

angyee commented 5 years ago

i am getting results like this, but how to display the result of image?

[{'rois': array([[244, 287, 590, 721], [216, 737, 426, 925]], dtype=int32), 'class': array([1, 1], dtype=int32), 'scores': array([0.9834276 , 0.76979005], dtype=float32), 'mask': array([[[False, False], [False, False], [False, False], ..., [False, False], [False, False], [False, False]],

   [[False, False],
    [False, False],
    [False, False],
    ...,
    [False, False],
    [False, False],
    [False, False]],

   [[False, False],
    [False, False],
    [False, False],
    ...,
    [False, False],
    [False, False],
    [False, False]],

   ...,

   [[False, False],
    [False, False],
    [False, False],
    ...,
    [False, False],
    [False, False],
    [False, False]],

   [[False, False],
    [False, False],
    [False, False],
    ...,
    [False, False],
    [False, False],
    [False, False]],

   [[False, False],
    [False, False],
    [False, False],
    ...,
    [False, False],
    [False, False],
    [False, False]]])}]

@bendangnuksung @buaacarzp

bendangnuksung commented 5 years ago

mask value is a list of boolean numpy arrays, in order to convert it to an image and display you can use:

mask_val = result['mask'][0]
mask_image = mask_val.astype(np.uint8) * 255
angyee commented 5 years ago

mask value is a list of boolean numpy arrays, in order to convert it to an image and display you can use:

mask_val = result['mask'][0]
mask_image = mask_val.astype(np.uint8) * 255

edit required in forward.py? where?

@bendangnuksung

angyee commented 5 years ago

mask_val = r['mask'][0] mask_image = mask_val.astype(np.uint8) * 255

print(r)

cv2.imshow('mask', mask_image) cv2.waitKey(0) cv2.destroyAllWindows()

Traceback (most recent call last): File "test.py", line 25, in mask_val = r['mask'][0] TypeError: list indices must be integers or slices, not str

@bendangnuksung

bendangnuksung commented 5 years ago

result is the variable you got after processing from the forward model.

result = [{'rois': array([[244, 287, 590, 721], [216, 737, 426, 925]], dtype=int32), 'class': array([1, 1], dtype=int32), 'scores': array([0.9834276 , 0.76979005], dtype=float32), 'mask': array([[[False, False], [False, False], [False, False], ...,

angyee commented 5 years ago

result is the variable you got after processing from the forward model.

result = [{'rois': array([[244, 287, 590, 721], [216, 737, 426, 925]], dtype=int32), 'class': array([1, 1], dtype=int32), 'scores': array([0.9834276 , 0.76979005], dtype=float32), 'mask': array([[[False, False], [False, False], [False, False], ...,

mask_val = r['mask'][0] change required mask_val = r[0]['mask]

but error is

Traceback (most recent call last): File "test.py", line 29, in cv2.imshow('mask', mask_image) cv2.error: OpenCV(4.1.0) /io/opencv/modules/imgproc/src/color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function 'cv::impl::{anonymous}::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::impl::{anonymous}::Set<3, 4>; VDcn = cv::impl::{anonymous}::Set<3, 4>; VDepth = cv::impl::{anonymous}::Set<0, 2, 5>; cv::impl::{anonymous}::SizePolicy sizePolicy = (cv::impl::::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'

Invalid number of channels in input image: 'VScn::contains(scn)' where 'scn' is 2

bendangnuksung commented 5 years ago

convert it to mask_val = r[0]['mask'][0] and see

angyee commented 5 years ago

convert it to mask_val = r[0]['mask'][0] and see

above line is working but, I have to show a masked image on my input image like this:

splash_20190611T122947

@bendangnuksung @bendangnuksung

angyee commented 5 years ago

from forward import ForwardModel import cv2 import numpy as np

frozen_graph_path = "/home/deepedge/mask_rcnn-master/mask_dent_frozen_graph.pb"

assign your own Config class

from config import mask_config my_config = mask_config(1)

forward_model = ForwardModel(frozen_graph_path, my_config)

def test_one_image(image): images = np.expand_dims(image, axis=0)

print(images)

results = forward_model(images)
return results

if name == "main": test_image_path = '/home/deepedge/mask_rcnn-master/mask-rcnn-bottle-training-master/dataset/val/car39.jpg' image = cv2.imread(test_image_path) rr = test_one_image(image) from mrcnn import visualize from mrcnn import model r = model.detect([rr], verbose=0)[0] visualize.display_instances(rr, r['rois'], r['masks'], r['class_ids'], dataset.class_names, r['scores']) print(type(r))

i have used There is a function called "display_instances" in the script "mrcnn/visualize.py" to visualize the results : not working? @bendangnuksung