open-mmlab / mmaction

An open-source toolbox for action understanding based on PyTorch
https://open-mmlab.github.io/
Apache License 2.0
1.86k stars 353 forks source link

Change number of classes in the model output layer #223

Open ayanasser opened 3 years ago

ayanasser commented 3 years ago

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)

zhaoyue-zephyrus commented 3 years ago

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.

ayanasser commented 3 years ago

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

zhaoyue-zephyrus commented 3 years ago

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}.