diff --git a/README.md b/README.md index 6117605..b6216a9 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ See [prepare dataset](docs/0.prepare_dataset.md). ### Train Train a model by ``` -CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 lib/main.py --cfgs ./config/baseline.yaml --phase train +CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 opengait/main.py --cfgs ./config/baseline.yaml --phase train ``` - `python -m torch.distributed.launch` [DDP](https://pytorch.org/tutorials/intermediate/ddp_tutorial.html) launch instruction. - `--nproc_per_node` The number of gpus to use, and it must equal the length of `CUDA_VISIBLE_DEVICES`. @@ -112,7 +112,7 @@ You can run commands in [train.sh](train.sh) for training different models. ### Test Evaluate the trained model by ``` -CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 lib/main.py --cfgs ./config/baseline.yaml --phase test +CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 opengait/main.py --cfgs ./config/baseline.yaml --phase test ``` - `--phase` Specified as `test`. - `--iter` Specify a iteration checkpoint. diff --git a/docs/1.detailed_config.md b/docs/1.detailed_config.md index 0d6d56e..21fc9b7 100644 --- a/docs/1.detailed_config.md +++ b/docs/1.detailed_config.md @@ -36,7 +36,7 @@ ### model_cfg * Model to be trained > * Args -> * model : Model type, please refer to [Model Library](../lib/modeling/models) for the supported values. +> * model : Model type, please refer to [Model Library](../opengait/modeling/models) for the supported values. > * **others** : Please refer to the [Training Configuration File of Corresponding Model](../config). ---- ### evaluator_cfg @@ -51,7 +51,7 @@ > - type: The name of sampler. Choose `InferenceSampler`. > - sample_type: In general, we use `all_ordered` to input all frames by its natural order, which makes sure the tests are consistent. > - batch_size: `int` values. -> - **others**: Please refer to [data.sampler](../lib/data/sampler.py) and [data.collate_fn](../lib/data/collate_fn.py) +> - **others**: Please refer to [data.sampler](../opengait/data/sampler.py) and [data.collate_fn](../opengait/data/collate_fn.py) > * transform: Support `BaseSilCuttingTransform`, `BaseSilTransform`. The difference between them is `BaseSilCuttingTransform` cut out the black pixels on both sides horizontally. > * metric: `euc` or `cos`, generally, `euc` performs better. @@ -73,7 +73,7 @@ > - batch_size: *[P,K]* where `P` denotes the subjects in training batch while the `K` represents the sequences every subject owns. **Example**: > - 8 > - 16 -> - **others**: Please refer to [data.sampler](../lib/data/sampler.py) and [data.collate_fn](../lib/data/collate_fn.py). +> - **others**: Please refer to [data.sampler](../opengait/data/sampler.py) and [data.collate_fn](../opengait/data/collate_fn.py). > * **others**: Please refer to `evaluator_cfg`. --- **Note**: diff --git a/docs/2.how_to_create_your_model.md b/docs/2.how_to_create_your_model.md index 4826e4e..7bb193b 100644 --- a/docs/2.how_to_create_your_model.md +++ b/docs/2.how_to_create_your_model.md @@ -50,11 +50,11 @@ class NewModel(BaseModel): > > `embeddings`, `logits` and `labels` are the input arguments of the loss function. -More information should be seen in [base_model.py](../lib/modeling/base_model.py) and [loss_aggregator.py](../lib/modeling/loss_aggregator.py). +More information should be seen in [base_model.py](../opengait/modeling/base_model.py) and [loss_aggregator.py](../opengait/modeling/loss_aggregator.py). After finishing the model file, you have two steps left to do: -**Step 1**: Put your newmodel.py under `lib/modeling/models`. +**Step 1**: Put your newmodel.py under `opengait/modeling/models`. **Step 2**: Specify the model name in a yaml file: ```yaml @@ -67,7 +67,7 @@ model_cfg: ## A new loss -If you want to write a new loss, you need to write a class inherited from `lib/modeling/losses`, like this +If you want to write a new loss, you need to write a class inherited from `opengait/modeling/losses`, like this ```python from .base import BaseLoss @@ -81,6 +81,6 @@ class NewLoss(BaseLoss): ``` Remember to use `gather_and_scale_wrapper` to wrap your forward function if your loss is computed by pairs like `triplet`. By this, we gather all features to one GPU card and scale the loss by the number of GPUs. -Then, put your loss in `lib/modeling/losses` so that you can use it in config file. +Then, put your loss in `opengait/modeling/losses` so that you can use it in config file. -Moreover, refer to [loss_aggregator.py](../lib/modeling/loss_aggregator.py) to explore how does your defined loss work in the model. +Moreover, refer to [loss_aggregator.py](../opengait/modeling/loss_aggregator.py) to explore how does your defined loss work in the model. diff --git a/docs/3.advanced_usages.md b/docs/3.advanced_usages.md index b194437..ffe6ea9 100644 --- a/docs/3.advanced_usages.md +++ b/docs/3.advanced_usages.md @@ -32,10 +32,10 @@ > * If your path structure is similar to [CASIA-B](http://www.cbsr.ia.ac.cn/english/Gait%20Databases.asp) (the 3-flod style: `id-type-view`), we recommand you to --> ### Data Augmentation -> In OpenGait, there is a basic transform class almost called by all the models, this is [BaseSilCuttingTransform](../lib/data/transform.py#L20), which is used to cut the input silhouettes. +> In OpenGait, there is a basic transform class almost called by all the models, this is [BaseSilCuttingTransform](../opengait/data/transform.py#L20), which is used to cut the input silhouettes. > > Accordingly, by referring to this implementation, you can easily customize the data agumentation in just two steps: -> * *Step1*: Define the transform function or class in [transform.py](../lib/data/transform.py), and make sure it callable. The style of [torchvision.transforms](https://pytorch.org/vision/stable/_modules/torchvision/transforms/transforms.html) is recommanded, and following shows a demo; +> * *Step1*: Define the transform function or class in [transform.py](../opengait/data/transform.py), and make sure it callable. The style of [torchvision.transforms](https://pytorch.org/vision/stable/_modules/torchvision/transforms/transforms.html) is recommanded, and following shows a demo; >> ```python >> import torchvision.transforms as T >> class demo1(): @@ -77,9 +77,9 @@ ### Visualization > To learn how does the model work, sometimes, you need to visualize the intermediate result. > -> For this purpose, we have defined a built-in instantiation of [`torch.utils.tensorboard.SummaryWriter`](https://pytorch.org/docs/stable/tensorboard.html), that is [`self.msg_mgr.writer`](../lib/utils/msg_manager.py#L24), to make sure you can log the middle information everywhere you want. +> For this purpose, we have defined a built-in instantiation of [`torch.utils.tensorboard.SummaryWriter`](https://pytorch.org/docs/stable/tensorboard.html), that is [`self.msg_mgr.writer`](../opengait/utils/msg_manager.py#L24), to make sure you can log the middle information everywhere you want. > -> Demo: if we want to visualize the output feature of [baseline's backbone](../lib/modeling/models/baseline.py#L27), we could just insert the following codes at [baseline.py#L28](../lib/modeling/models/baseline.py#L28): +> Demo: if we want to visualize the output feature of [baseline's backbone](../opengait/modeling/models/baseline.py#L27), we could just insert the following codes at [baseline.py#L28](../opengait/modeling/models/baseline.py#L28): >> ```python >> summary_writer = self.msg_mgr.writer >> if torch.distributed.get_rank() == 0 and self.training and self.iteration % 100==0: diff --git a/misc/GREW/README.md b/misc/GREW/README.md index 985781f..0ca8999 100644 --- a/misc/GREW/README.md +++ b/misc/GREW/README.md @@ -64,13 +64,13 @@ Then you will see the structure like: ## Train the dataset Modify the `dataset_root` in `./config/baseline_GREW.yaml`, and then run this command: ```shell -CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 lib/main.py --cfgs ./config/baseline_GREW.yaml --phase train +CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 opengait/main.py --cfgs ./config/baseline_GREW.yaml --phase train ``` ## Get the submission file ```shell -CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 lib/main.py --cfgs ./config/baseline_GREW.yaml --phase test +CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 opengait/main.py --cfgs ./config/baseline_GREW.yaml --phase test ``` The result will be generated in your working directory, you must rename and compress it as the requirements before submitting. diff --git a/misc/HID/README.md b/misc/HID/README.md index ea4dedb..2eb3367 100644 --- a/misc/HID/README.md +++ b/misc/HID/README.md @@ -12,13 +12,13 @@ python misc/HID/pretreatment_HID.py --input_train_path="train" --input_gallery_p ## Train the dataset Modify the `dataset_root` in `./misc/HID/baseline_hid.yaml`, and then run this command: ```shell -CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 lib/main.py --cfgs ./misc/HID/baseline_hid.yaml --phase train +CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 opengait/main.py --cfgs ./misc/HID/baseline_hid.yaml --phase train ``` You can also download the [trained model](https://github.com/ShiqiYu/OpenGait/releases/download/v1.1/pretrained_hid_model.zip) and place it in `output` after unzipping. ## Get the submission file ```shell -CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 lib/main.py --cfgs ./misc/HID/baseline_hid.yaml --phase test +CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 opengait/main.py --cfgs ./misc/HID/baseline_hid.yaml --phase test ``` The result will be generated in your working directory. diff --git a/lib/data/__init__.py b/opengait/data/__init__.py similarity index 100% rename from lib/data/__init__.py rename to opengait/data/__init__.py diff --git a/lib/data/collate_fn.py b/opengait/data/collate_fn.py similarity index 100% rename from lib/data/collate_fn.py rename to opengait/data/collate_fn.py diff --git a/lib/data/dataset.py b/opengait/data/dataset.py similarity index 100% rename from lib/data/dataset.py rename to opengait/data/dataset.py diff --git a/lib/data/sampler.py b/opengait/data/sampler.py similarity index 100% rename from lib/data/sampler.py rename to opengait/data/sampler.py diff --git a/lib/data/transform.py b/opengait/data/transform.py similarity index 100% rename from lib/data/transform.py rename to opengait/data/transform.py diff --git a/lib/main.py b/opengait/main.py similarity index 100% rename from lib/main.py rename to opengait/main.py diff --git a/lib/modeling/backbones/__init__.py b/opengait/modeling/backbones/__init__.py similarity index 100% rename from lib/modeling/backbones/__init__.py rename to opengait/modeling/backbones/__init__.py diff --git a/lib/modeling/backbones/plain.py b/opengait/modeling/backbones/plain.py similarity index 100% rename from lib/modeling/backbones/plain.py rename to opengait/modeling/backbones/plain.py diff --git a/lib/modeling/base_model.py b/opengait/modeling/base_model.py similarity index 99% rename from lib/modeling/base_model.py rename to opengait/modeling/base_model.py index d5082a9..c945712 100644 --- a/lib/modeling/base_model.py +++ b/opengait/modeling/base_model.py @@ -2,7 +2,7 @@ This module defines the abstract meta model class and base model class. In the base model, we define the basic model functions, like get_loader, build_network, and run_train, etc. - The api of the base model is run_train and run_test, they are used in `lib/main.py`. + The api of the base model is run_train and run_test, they are used in `opengait/main.py`. Typical usage: diff --git a/lib/modeling/loss_aggregator.py b/opengait/modeling/loss_aggregator.py similarity index 100% rename from lib/modeling/loss_aggregator.py rename to opengait/modeling/loss_aggregator.py diff --git a/lib/modeling/losses/__init__.py b/opengait/modeling/losses/__init__.py similarity index 100% rename from lib/modeling/losses/__init__.py rename to opengait/modeling/losses/__init__.py diff --git a/lib/modeling/losses/base.py b/opengait/modeling/losses/base.py similarity index 100% rename from lib/modeling/losses/base.py rename to opengait/modeling/losses/base.py diff --git a/lib/modeling/losses/softmax.py b/opengait/modeling/losses/softmax.py similarity index 100% rename from lib/modeling/losses/softmax.py rename to opengait/modeling/losses/softmax.py diff --git a/lib/modeling/losses/triplet.py b/opengait/modeling/losses/triplet.py similarity index 100% rename from lib/modeling/losses/triplet.py rename to opengait/modeling/losses/triplet.py diff --git a/lib/modeling/models/__init__.py b/opengait/modeling/models/__init__.py similarity index 100% rename from lib/modeling/models/__init__.py rename to opengait/modeling/models/__init__.py diff --git a/lib/modeling/models/baseline.py b/opengait/modeling/models/baseline.py similarity index 100% rename from lib/modeling/models/baseline.py rename to opengait/modeling/models/baseline.py diff --git a/lib/modeling/models/gaitgl.py b/opengait/modeling/models/gaitgl.py similarity index 100% rename from lib/modeling/models/gaitgl.py rename to opengait/modeling/models/gaitgl.py diff --git a/lib/modeling/models/gaitpart.py b/opengait/modeling/models/gaitpart.py similarity index 100% rename from lib/modeling/models/gaitpart.py rename to opengait/modeling/models/gaitpart.py diff --git a/lib/modeling/models/gaitset.py b/opengait/modeling/models/gaitset.py similarity index 100% rename from lib/modeling/models/gaitset.py rename to opengait/modeling/models/gaitset.py diff --git a/lib/modeling/models/gln.py b/opengait/modeling/models/gln.py similarity index 100% rename from lib/modeling/models/gln.py rename to opengait/modeling/models/gln.py diff --git a/lib/modeling/modules.py b/opengait/modeling/modules.py similarity index 100% rename from lib/modeling/modules.py rename to opengait/modeling/modules.py diff --git a/lib/utils/__init__.py b/opengait/utils/__init__.py similarity index 100% rename from lib/utils/__init__.py rename to opengait/utils/__init__.py diff --git a/lib/utils/common.py b/opengait/utils/common.py similarity index 100% rename from lib/utils/common.py rename to opengait/utils/common.py diff --git a/lib/utils/evaluation.py b/opengait/utils/evaluation.py similarity index 100% rename from lib/utils/evaluation.py rename to opengait/utils/evaluation.py diff --git a/lib/utils/msg_manager.py b/opengait/utils/msg_manager.py similarity index 100% rename from lib/utils/msg_manager.py rename to opengait/utils/msg_manager.py diff --git a/test.sh b/test.sh index 20e7db1..3ed516b 100644 --- a/test.sh +++ b/test.sh @@ -1,32 +1,32 @@ # # **************** For CASIA-B **************** # # Baseline -CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 lib/main.py --cfgs ./config/baseline.yaml --phase test +CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 opengait/main.py --cfgs ./config/baseline.yaml --phase test # # GaitSet -# CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 lib/main.py --cfgs ./config/gaitset.yaml --phase test +# CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 opengait/main.py --cfgs ./config/gaitset.yaml --phase test # # GaitPart -# CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 lib/main.py --cfgs ./config/gaitpart.yaml --phase test +# CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 opengait/main.py --cfgs ./config/gaitpart.yaml --phase test # GaitGL -# CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --master_port 12345 --nproc_per_node=4 lib/main.py --cfgs ./config/gaitgl.yaml --phase test +# CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --master_port 12345 --nproc_per_node=4 opengait/main.py --cfgs ./config/gaitgl.yaml --phase test # # GLN # # Phase 1 -# CUDA_VISIBLE_DEVICES=3,4 python -m torch.distributed.launch --master_port 12345 --nproc_per_node=2 lib/main.py --cfgs ./config/gln/gln_phase1.yaml --phase test +# CUDA_VISIBLE_DEVICES=3,4 python -m torch.distributed.launch --master_port 12345 --nproc_per_node=2 opengait/main.py --cfgs ./config/gln/gln_phase1.yaml --phase test # # Phase 2 -# CUDA_VISIBLE_DEVICES=2,5 python -m torch.distributed.launch --nproc_per_node=2 lib/main.py --cfgs ./config/gln/gln_phase2.yaml --phase test +# CUDA_VISIBLE_DEVICES=2,5 python -m torch.distributed.launch --nproc_per_node=2 opengait/main.py --cfgs ./config/gln/gln_phase2.yaml --phase test # # **************** For OUMVLP **************** # # Baseline -# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 lib/main.py --cfgs ./config/baseline_OUMVLP.yaml --phase test +# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 opengait/main.py --cfgs ./config/baseline_OUMVLP.yaml --phase test # # GaitSet -# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 lib/main.py --cfgs ./config/gaitset_OUMVLP.yaml --phase test +# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 opengait/main.py --cfgs ./config/gaitset_OUMVLP.yaml --phase test # # GaitPart -# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 lib/main.py --cfgs ./config/gaitpart_OUMVLP.yaml --phase test +# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 opengait/main.py --cfgs ./config/gaitpart_OUMVLP.yaml --phase test # GaitGL -# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 lib/main.py --cfgs ./config/gaitgl_OUMVLP.yaml --phase test +# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 opengait/main.py --cfgs ./config/gaitgl_OUMVLP.yaml --phase test diff --git a/train.sh b/train.sh index b2b1718..b41e9d4 100644 --- a/train.sh +++ b/train.sh @@ -1,32 +1,32 @@ # # **************** For CASIA-B **************** # # Baseline -CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 lib/main.py --cfgs ./config/baseline.yaml --phase train +CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 opengait/main.py --cfgs ./config/baseline.yaml --phase train # # GaitSet -# CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 lib/main.py --cfgs ./config/gaitset.yaml --phase train +# CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 opengait/main.py --cfgs ./config/gaitset.yaml --phase train # # GaitPart -# CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 lib/main.py --cfgs ./config/gaitpart.yaml --phase train +# CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 opengait/main.py --cfgs ./config/gaitpart.yaml --phase train # GaitGL -# CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 lib/main.py --cfgs ./config/gaitgl.yaml --phase train +# CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 opengait/main.py --cfgs ./config/gaitgl.yaml --phase train # # GLN # # Phase 1 -# CUDA_VISIBLE_DEVICES=2,5,6,7 python -m torch.distributed.launch --nproc_per_node=4 lib/main.py --cfgs ./config/gln/gln_phase1.yaml --phase train +# CUDA_VISIBLE_DEVICES=2,5,6,7 python -m torch.distributed.launch --nproc_per_node=4 opengait/main.py --cfgs ./config/gln/gln_phase1.yaml --phase train # # Phase 2 -# CUDA_VISIBLE_DEVICES=2,5,6,7 python -m torch.distributed.launch --nproc_per_node=4 lib/main.py --cfgs ./config/gln/gln_phase2.yaml --phase train +# CUDA_VISIBLE_DEVICES=2,5,6,7 python -m torch.distributed.launch --nproc_per_node=4 opengait/main.py --cfgs ./config/gln/gln_phase2.yaml --phase train # # **************** For OUMVLP **************** # # Baseline -# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 lib/main.py --cfgs ./config/baseline_OUMVLP.yaml --phase train +# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 opengait/main.py --cfgs ./config/baseline_OUMVLP.yaml --phase train # # GaitSet -# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 lib/main.py --cfgs ./config/gaitset_OUMVLP.yaml --phase train +# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 opengait/main.py --cfgs ./config/gaitset_OUMVLP.yaml --phase train # # GaitPart -# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 lib/main.py --cfgs ./config/gaitpart_OUMVLP.yaml --phase train +# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 opengait/main.py --cfgs ./config/gaitpart_OUMVLP.yaml --phase train # GaitGL -# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 lib/main.py --cfgs ./config/gaitgl_OUMVLP.yaml --phase train \ No newline at end of file +# CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 opengait/main.py --cfgs ./config/gaitgl_OUMVLP.yaml --phase train \ No newline at end of file