FlyEgle / MAE-pytorch

Masked Autoencoders Are Scalable Vision Learners
247 stars 36 forks source link

Maybe have some bugs in finetune #6

Closed Nioolek closed 2 years ago

Nioolek commented 2 years ago

It seems that the losses are different between training_mae and finetune.When training mae and finetune, there is no distinction between the different cases in the forward function.But when calculating loss, finetune receives two variables while Training_mae only receives one.

` with autocast():

        if args.finetune:

            # one variable?

            outputs = model(inputs)

            losses = criterion(outputs, targets)

        else:

            # two variables?

            outputs, mask_index = model(inputs)

            print('shapex', outputs.shape, type(mask_index))

            mask = build_mask(mask_index, args.patch_size, args.crop_size)

            losses = criterion(outputs, inputs, mask)

`

Code in model forward: ` def forward(self, x):

batch, c, h, w

    norm_embeeding, sample_index, mask_index = self.Encoder.autoencoder(x)
    proj_embeeding = self.proj(norm_embeeding)
    decode_embeeding = self.Decoder.decoder(proj_embeeding, sample_index, mask_index)
    outputs = self.restruction(decode_embeeding)

    cls_token = outputs[:, 0, :]
    image_token = outputs[:, 1:, :] # (b, num_patches, patches_vector)
    # cal the mask patches normalization Independent
    image_norm_token = self.patch_norm(image_token)
    n, l, dim = image_norm_token.shape
    image_norm_token = image_norm_token.view(-1, self.num_patch[0], self.num_patch[1], dim).permute(0, 3, 1, 2)
    restore_image = self.unconv(image_norm_token)
    # return same variables in both training_mae and finetune
    return restore_image, mask_index`
FlyEgle commented 2 years ago

dataset have some error,my local is diff with online code,i commmit the new code after a moment

FlyEgle commented 2 years ago

My local is train on two python script, online code for easy show, i merge them into one script. I close the issue, if you have other quesition, pls open again.Thank for you review code.

Nioolek commented 2 years ago

Thanks to the author for open source related source code