Giter Site home page Giter Site logo

Comments (10)

akolesnikoff avatar akolesnikoff commented on September 7, 2024 2

Hi @owmohamm and sorry for the late reply.

AFAIK weight decay does not have significant regularization effect in the modern networks that have normalization layers (e.g. LayerNorm) or standardized weights. I can recommend to look into this two references to understand this effect:

  1. L2 Regularization versus Batch and Weight Normalization by Laarhoven: https://arxiv.org/abs/1706.05350.
  2. An Exponential Learning Rate Schedule for Deep Learning by Li and Arora - https://arxiv.org/abs/1910.07454.

Hope it helps.

from vision_transformer.

andsteing avatar andsteing commented on September 7, 2024

Hello!

  1. The checkpoints published in this repository were pretrained for 90 epochs.
  2. Same data augmentation and model initialization
  3. We use sigmoid cross entropy (see e.g. tf.nn.softmax_cross_entropy_with_logits) - you could implement this as follows:
def sigmoid_xent(*, logits, labels):
  log_p = jax.nn.log_sigmoid(logits)
  log_not_p = jax.nn.log_sigmoid(-logits)
  nll = -jnp.sum(labels * log_p + (1. - labels) * log_not_p, axis=-1)
  return jnp.mean(nll)

Best!

from vision_transformer.

owmohamm avatar owmohamm commented on September 7, 2024

Thanks for the info!!

Just to confirm, you were referring to tf.nn.sigmoid_cross_entropy_with_logits and not tf.nn.softmax_cross_entropy_with_logits, right?

In regards to the weight decay, what value was used and was it applied to full model or were the bias and norm terms excluded? When I try to pretrain the model the bias terms tend to grow much larger than those in the released weights

from vision_transformer.

andsteing avatar andsteing commented on September 7, 2024

You're 100% right, that was an unfortunate typo on my side!

As for weight decay, we used weight_decay=0.1 and we apply the following function to all kernel weights:

def decay_weight_fn(w, lr, weight_decay):
  return (1.0 - lr * decay) * w if decay else w

As for bias terms, we initialized the head biases to -10 :

params["head"]["bias"] = jnp.full_like(params["head"]["bias"], -10.)

HTH

from vision_transformer.

owmohamm avatar owmohamm commented on September 7, 2024

Thanks for your help!!, that resolves any questions I had.

from vision_transformer.

andsteing avatar andsteing commented on September 7, 2024

Correction : Actually, for the relevant pretraining run, we used flax.optim.Adam(weight_decay=0.1) instead of the manual version that I described above (so this would indeed apply to the weight decay to all the weights).

from vision_transformer.

owmohamm avatar owmohamm commented on September 7, 2024

That's interesting, was this done to combat overfitting?
In my experiments (not this architecture but in general) I've noticed that adding weight decay for the bias terms usually gives an inferior model, but in this case i.e. pretraining ViT-L/16 on imagenet-21k the model tends to overfit quite easily.

from vision_transformer.

pengzhiliang avatar pengzhiliang commented on September 7, 2024

Hello, everyone, @owmohamm @andsteing @akolesnikoff . I meet some same questions when pretrain the ViT-B/16 architecture on imagenet-21k:

  1. I also find that the bias in our weight in larger than the released weights.
    As you says, do I need to apply the weight decay to all weight items including bias and norm? Then, should all the biases be initialized to -10 or is it just the bias of the final classifier?

params["head"]["bias"] = jnp.full_like(params["head"]["bias"], -10.)

  1. About the multilabel.
    Where should I download multilabel information? Or does it mean that the same image in the 21k dataset of 14M already belongs to different classes? I'm not sure.
  2. When I use softmax cross entropy loss, the value of loss after pre-training is about 1.75. However, when using sigmoid cross-entropy loss, the 10th epoch is only about 0.0003. I am not sure if something is wrong.

I have been troubled by these for a long time and hope to get help, thank u very mch!

from vision_transformer.

andsteing avatar andsteing commented on September 7, 2024

To your questions:

  1. We used flax.optim.Adam(weight_decay=0.1) during pre-training for these models. Only final classifier head biases were initialized.
  2. As for ImageNet21k dataset multi-labeledness, see e.g. ImageNet-21K Pretraining for the Masses. Note that JFT is also multi-label, but ImageNet-1k is not (note that we also use sigmoid loss for ImageNet-1k though, see #62)
  3. With the implementation above you should get loss curves that resemble what I posted in #62

from vision_transformer.

pengzhiliang avatar pengzhiliang commented on September 7, 2024

Ok, thank u very much!

from vision_transformer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.