0

I have project in brain tumor classification, but i'm dealing with this error for about 3 weeks, this is the error message

ERROR:
    root:Error processing image {'id': 'tumor-44.png', 'source': 'Meningioma', 
                                 'path': 'D:\Belajar Machine Learning\Coba Mask Tumor\dataset\images\tumor-44.png'}  
    Traceback (most recent call last): 
        File "D:\Belajar Machine Learning\Coba Mask Tumor\mrcnn\model.py", line 1709, in data_generator use_mini_mask=config.USE_MINI_MASK) 
          File "D:\Belajar Machine Learning\Coba Mask Tumor\mrcnn\model.py", line 1212, in load_image_gt 
          mask, class_ids = dataset.load_mask(image_id) File "tumor.py", line 228, in load_mask 
               mask = np.zeros([info["height"], info["width"], len(info["polygons"])], 
        KeyError: 'height'

I'm so confused with that error message, some people say because something wrong with the json file when I'm mask the image because not using polygon masking, even though I already use polygon for masking.

This is where i'm gonna load my JSON code:

DATASET_PATH = os.path.abspath("dataset")
IMAGES_PATH = os.path.sep.join([DATASET_PATH, "images"])
ANNOT_PATH = os.path.sep.join([DATASET_PATH, "fix.json"])

JSON code

This is the load_mask code:

def load_mask(self, imageID):

    # Convert polygons to a bitmap mask of shape
    # [height, width, instance_count]

     info = self.image_info[imageID]
     mask = np.zeros([info["height"], info["width"], len(info["polygons"])],
                     dtype=np.uint8)
     for i, p in enumerate(info["polygons"]):
         # Get indexes of pixels inside the polygon and set them to 1
         rr, cc = skimage.draw.polygon(p['all_points_y'], p['all_points_x'])

         ## Note that this modifies the existing array arr, instead of creating a result array
         ## Ref: https://stackoverflow.com/questions/19666626/replace-all-elements-of-python-numpy-array-that-are-greater-than-some-value
         rr[rr > mask.shape[0] - 1] = mask.shape[0] - 1
         cc[cc > mask.shape[1] - 1] = mask.shape[1] - 1

         mask[rr, cc, i] = 1

     return mask.astype(np.bool), np.ones([mask.shape[-1]], dtype=np.int32)

I've succeeded the training but i achieve that with round masking, but I want it with polygon masking though.

Thank you.

shandytp
  • 41
  • 1
  • 6
  • 1
    Can you share the data or link to it and reference which file is the problematic one? Have you tried inspecting the json data with an IDE? Some IDE's like Brackets will tell you if the JSON data is malformed. – datawrestler Jan 04 '20 at 18:15
  • 1
    Do you have a [mcve]? Have you narrowed down the error? – AMC Jan 04 '20 at 18:18
  • Seems like it might be a bug with the code you're using, if it works with round masking but not polygon masking. Might be worth a git issue for the maintainers of the code. Or perhaps height isn't relevant to polygon masking where it is relevant to round masking? It doesn't sound like we have enough information about the problem at hand to propose solutions. – David Parks Jan 04 '20 at 18:21
  • i think the problem is in this code `mask = np.zeros([info["height"], info["width"], len(info["polygons"])],dtype=np.uint8)` , i already try change `"height"` or `"width"` with `"all_points_y"` still got that error message @AMC i'm using the code from [source code](https://github.com/matterport/Mask_RCNN) and edit it little bit @DavidParks – shandytp Jan 04 '20 at 18:30
  • Well yes obviously that's where the error **appears**, I'm talking about isolating the area where things first veer from what you expect. – AMC Jan 04 '20 at 18:31
  • this is the JSON data [JSON data](https://pastebin.com/u6N8k0Sa), when i open it in Brackets half code are with color and half the code are gray color, is it good thing? @datawrestler i'm sorry can you explain it what you mean more easier? because i'm kinda confuse right now – shandytp Jan 04 '20 at 18:39
  • Are you sure the code you are using is meant to load the JSON ground truth files that you have? If you use the wrong code or JSON files then you will get tons of errors that are not easy to fix. – Dr. Snoopy Jan 04 '20 at 19:57
  • this the code where i'm gonna load my JSON files `DATASET_PATH = os.path.abspath("dataset") IMAGES_PATH = os.path.sep.join([DATASET_PATH, "images"]) ANNOT_PATH = os.path.sep.join([DATASET_PATH, "fix.json"])` @MatiasValdenegro – shandytp Jan 05 '20 at 05:32
  • @shandytp I think at this point we really need a [mcve]. It gets extremely difficult to follow a bunch of code snippets. – AMC Jan 05 '20 at 07:43
  • ok already fix that – shandytp Jan 05 '20 at 09:27
  • You didn't understand my question, you don't seem to understand that there are more fundamental issues than just fixing an error. – Dr. Snoopy Jan 05 '20 at 10:10

0 Answers0