Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build_Mask function - missing image size in Keypoints dataset #18

Closed
kkoripl opened this issue Feb 15, 2021 · 1 comment
Closed

Build_Mask function - missing image size in Keypoints dataset #18

kkoripl opened this issue Feb 15, 2021 · 1 comment

Comments

@kkoripl
Copy link
Contributor

kkoripl commented Feb 15, 2021

Hi,

Another one with shapes, as I was almost killing myself few times, why losses are throwing incompatible shapes error:

InvalidArgumentError:  Incompatible shapes: [2,320,320,30] vs. [2,512,512,30]
	 [[node gradients_1/loss_2/softmax_loss/dice_loss_plus_1focal_loss/mul_grad/BroadcastGradientArgs (defined at /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3009) ]] [Op:__inference_keras_scratch_graph_156811]

when all my pictures are of 512x512 size. Losses are getting 2 arguments of ground-truth and predictions, which are tensors of shapes: batch_size, image_height, image_width, classes, so the change need to be made beforehand and I think it's on the preprocessing staff.

In Keypoints dataset general class Dataset has function getItem and inside of it:

        mask = _build_mask(keypoints)

        # extract certain classes from mask (e.g. cars)
        masks = [(mask == v) for v in self.class_values]
        mask = np.stack(masks, axis=-1).astype("float")

        # add background if mask is not binary
        if mask.shape[-1] != 1:
            background = 1 - mask.sum(axis=-1, keepdims=True)
            mask = np.concatenate((mask, background), axis=-1)

        # apply augmentations
        if self.augmentation:
            sample = self.augmentation(image=image, mask=mask)
            image, mask = sample["image"], sample["mask"]

Everything looks fine, but, _build_mask_utils has some default values:

def _build_mask(keypoints, mask_shape=(320, 320), nb_of_mask=29):

I don't know what exactly module of augumentation does, but it looks like mask is changing shape of a validation image, so when to compare against old one, incompatible shapes error is thrown.

My idea is to invoke _build_mask like so:

mask = _build_mask(keypoints, mask_shape = image.shape)
@DonsetPG
Copy link
Owner

Hey,

Again yes good catch. I am very sorry I taught I removed such hardcoded shape in every training scripts...
Anyway, this should be corrected with the last commit.

Feel free to open a pull request next time haha!
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants