mmaction icon indicating copy to clipboard operation
mmaction copied to clipboard

Change number of classes in the model output layer

Open ayanasser opened this issue 4 years ago • 3 comments

Hi, Do you have the ability for finetuning slowfast model but with 2 classes only? in another word (could I change the number of classes of the last layer of "pretrained slowfastNet model" For a summary, I want to take the feature from that pretrained model then classify those features with a simple 2 dense layers, but I need to end up with one model, not 2 models (one for feature extraction and the other for classifying)

ayanasser avatar Dec 01 '20 15:12 ayanasser

Hi, I think a simple modification on the classification head (https://github.com/open-mmlab/mmaction/blob/master/mmaction/models/tenons/cls_heads/cls_head.py) can do this.

zhaoyue-zephyrus avatar Dec 03 '20 08:12 zhaoyue-zephyrus

Hi @zhaoyue-zephyrus , thank u, but Does this modification guarantee that all layers above the classifier layers are frozen?

ayanasser avatar Dec 03 '20 13:12 ayanasser

You may need to change the frozen_stages in the config (https://github.com/open-mmlab/mmaction/blob/master/configs/SlowOnly/slowonly_kinetics400_se_rgb_r50_seg1_8x8_scratch.py#L9) to be a non-negative value to ensure this. For example, frozen_stages=3 means that you are freezing weights in conv1 and res{2,3,4}.

zhaoyue-zephyrus avatar Dec 03 '20 17:12 zhaoyue-zephyrus