martinwholtmon / IT3920-2024-Master-MSIT

Master project for MSIT 2024 - Towards Efficient Human Action Recognition: The Role of Keyframe Selection in Video Processing
MIT License
0 stars 0 forks source link

create arg parser #10

Closed martinwholtmon closed 8 months ago

martinwholtmon commented 9 months ago

A lot of my arguments could be parsed through the command line to make it simpler to run multiple instances of the model.

E.g.:

run_class_finetuning.py \
    --model ViT-B/16 \
    --data_set Kinetics-400 \
    --nb_classes 400 \
    --data_path ${DATA_PATH} \
    --log_dir ${OUTPUT_DIR} \
    --output_dir ${OUTPUT_DIR} \
    --batch_size 16 \
    --input_size 224 \
    --short_side_size 224 \
    --save_ckpt_freq 5 \
    --num_frames 8 \
    --embed_dim 512 \
    --opt adamw \
    --lr 3e-4 \
    --layer_decay 0.65 \
    --opt_betas 0.9 0.999 \
    --weight_decay 0.05 \
    --epochs 20 \
    --drop_path 0. \
    --drop 0. \
    --dist_eval \
    --enable_deepspeed

Take inspiration from https://github.com/whwu95/ATM/

To build the arg parser for Torch Lightning:

from argparse import ArgumentParser

parser = ArgumentParser()

# Trainer arguments
parser.add_argument("--devices", type=int, default=2)

# Hyperparameters for the model
parser.add_argument("--layer_1_dim", type=int, default=128)

# Parse the user inputs and defaults (returns a argparse.Namespace)
args = parser.parse_args()

# Use the parsed arguments in your program
trainer = Trainer(devices=args.devices)
model = MyModel(layer_1_dim=args.layer_1_dim)
python trainer.py --layer_1_dim 64 --devices 1
martinwholtmon commented 9 months ago

Maybe see here, create static argparser inside the module class: https://pytorch-lightning.readthedocs.io/en/0.9.0/hyperparameters.html#multiple-lightning-modules