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

Questions about Train #37

Open
wanan0414 opened this issue Sep 9, 2024 · 5 comments
Open

Questions about Train #37

wanan0414 opened this issue Sep 9, 2024 · 5 comments

Comments

@wanan0414
Copy link

I'm going to do a radar signal classification task, and using the pre-training weights from imagenet isn't appropriate. I also don't have enough dataset for pre-training here, is it possible to train directly with supervised learning using only a training set with 22000 data volume and a test set? Looking forward to your answer!

@ahatamiz
Copy link
Collaborator

ahatamiz commented Sep 9, 2024

Hi @wanan0414

Yes ! the codebase supports training on any datasets for classification tasks. Here's a command prompt assuming you are running on 8 GPUs (but it is also easy to extend for multi-node setup). You need to specify DATA_PATH_TRAIN and DATA_PATH_VAL for your train and validation (test) sets, respectively.

Although I recommend trying different learning rates LR and batch sizes BS for your setup.

Needless to say, any of our MambaVision variants can be specified such as mamba_vision_T.

#!/bin/bash

MODEL=mamba_vision_T
DATA_PATH_TRAIN="/my_dataset/train"
DATA_PATH_VAL="/my_dataset/val"
BS=256
EXP=my_experiment
LR=5e-4
WD=0.05
DR=0.2

torchrun --nproc_per_node=8 train.py --input-size 3 224 224 --crop-pct=0.875 \
--train-split=$DATA_PATH_TRAIN --val-split=$DATA_PATH_VAL --model $MODEL --amp --weight-decay ${WD} --drop-path ${DR} --batch-size $BS --tag $EXP --lr $LR

Hope this helps but let me know if there's any issue.

@ahatamiz
Copy link
Collaborator

ahatamiz commented Sep 9, 2024

The above also assumes that images of each class are placed within the same folder under both train or validation as shown in the following:

├── train
│   ├── class1
│   │   ├── img1.jpeg
│   │   ├── img2.jpeg
│   │   └── ...
│   ├── class2
│   │   ├── img3.jpeg
│   │   └── ...
│   └── ...
└── val
    ├── class1
    │   ├── img4.jpeg
    │   ├── img5.jpeg
    │   └── ...
    ├── class2
    │   ├── img6.jpeg
    │   └── ...
    └── ...

@wanan0414
Copy link
Author

Hi @ahatamiz
Thank you very much for your reply! My dataset is in the same format as the train-val you mentioned. Thank you for providing the schematic code. A new question I have is in that case do I not use validate.py and just focus on the train.py file?

@ahatamiz
Copy link
Collaborator

ahatamiz commented Sep 10, 2024

Hi @wanan0414

In this case, validate.py can be used to test the model's performance on your test set, assuming it's different from your validation set.

@wanan0414
Copy link
Author

wanan0414 commented Sep 19, 2024

Hello! Thank you for your previous answer.
Now I have a new question about the model parameters.
My image is 1×64×64 grayscale and the whole training set is only 22000 and test set 5500 . So I guess it might not be appropriate to use these parameters you gave directly.

def mamba_vision_T(pretrained=False, **kwargs):
    model_path = kwargs.pop("model_path", "/tmp/mamba_vision_T.pth.tar")
    depths = kwargs.pop("depths", [1, 3, 8, 4])
    num_heads = kwargs.pop("num_heads", [2, 4, 8, 16])
    window_size = kwargs.pop("window_size", [8, 8, 14, 7])
    dim = kwargs.pop("dim", 80)
    in_dim = kwargs.pop("in_dim", 32)
    mlp_ratio = kwargs.pop("mlp_ratio", 4)
    resolution = kwargs.pop("resolution", 224)
    drop_path_rate = kwargs.pop("drop_path_rate", 0.2)
    pretrained_cfg = resolve_pretrained_cfg('mamba_vision_T').to_dict()
    update_args(pretrained_cfg, kwargs, kwargs_filter=None)
    model = MambaVision(depths=[1, 3, 8, 4],
                        num_heads=[2, 4, 8, 16],
                        window_size=[8, 8, 14, 7],
                        dim=80,
                        in_dim=32,
                        mlp_ratio=4,
                        resolution=224,
                        drop_path_rate=0.2,
                        **kwargs)
    model.pretrained_cfg = pretrained_cfg
    model.default_cfg = model.pretrained_cfg
    if pretrained:
        if not Path(model_path).is_file():
            url = model.default_cfg['url']
            torch.hub.download_url_to_file(url=url, dst=model_path)
        model._load_state_dict(model_path)
    return model

Do you have some suggestions for me regarding the modification of the dim, in_dim, depths, etc. parameters in this part of the code?

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