Mustafa Aktaş
Mustafa Aktaş

Reputation: 103

Mask-RCNN, ValueError: could not broadcast input array from shape (70) into shape (1)

I am working on a project that detects buildings on SpaceNet dataset by using Mask-RCNN. When I run this code:

model.train(dataset_train, dataset_val, 
            learning_rate=config.LEARNING_RATE, 
            epochs=1, 
            layers='heads')

I got this error:

    1772             batch_images[b] = mold_image(image.astype(np.float32), config)

-> 1773             batch_gt_class_ids[b, :gt_class_ids.shape[0]] = gt_class_ids

   1774             batch_gt_boxes[b, :gt_boxes.shape[0]] = gt_boxes

   1775             batch_gt_masks[b, :, :, :gt_masks.shape[-1]] = gt_masks

ValueError: could not broadcast input array from shape (70) into shape (1)

And also got this warning: Warning Messages

When I debug the variables: 'gt_class_ids' and 'batch_gt_class_ids', I got this:

Debug Image

Upvotes: 2

Views: 868

Answers (2)

Mustafa Aktaş
Mustafa Aktaş

Reputation: 103

As @Mahesh said, I debugged the variable gt_class_ids and realized that the shape of it was (x, 1). 'x' could be 70, 15 or whatever it is, the problem was about the gt_class_ids.shape[0] part. gt_class_ids.shape[0] gives us 'x', and x again can be any number. So I went to the

model.py

(The direction of mine was: C:\Users\MUSTAFAAKTAS\Desktop\SpaceNet_MaskRCNN\mrcnn\model.py)

file and changed to batch_gt_class_ids[b, :gt_class_ids.shape[1]] = gt_class_ids

instead batch_gt_class_ids[b, :gt_class_ids.shape[0]] = gt_class_ids.

So, it return '1' instead of 'x'.

This solution worked for me :)

Upvotes: 1

Mahesh
Mahesh

Reputation: 163

ValueError: could not broadcast input array from shape (70) into shape (1) means that there is an array shape mismatch in the line 1773 batch_gt_boxes[b, :gt_boxes.shape[0]] = gt_boxes to be more specific your trying to broadcast values from an array of shape 70 to an array of shape 1.

Can you run a debugger on this script and share the value of gt_class_ids and batch_gt_class_ids? This can help solve the problem better. Thanks

Upvotes: 0

Related Questions