diff options
-rw-r--r-- | config.py | 4 | ||||
-rw-r--r-- | models/model.py | 35 | ||||
-rw-r--r-- | startup | 2 | ||||
-rw-r--r-- | utils/configuration.py | 95 | ||||
-rw-r--r-- | utils/misc.py | 5 |
5 files changed, 20 insertions, 121 deletions
@@ -1,6 +1,4 @@ -from utils.configuration import Configuration - -config: Configuration = { +config = { 'system': { # Disable accelerator 'disable_acc': False, diff --git a/models/model.py b/models/model.py index 591808a..f4654f3 100644 --- a/models/model.py +++ b/models/model.py @@ -13,9 +13,6 @@ from torch.utils.tensorboard import SummaryWriter from tqdm import tqdm from models.rgb_part_net import RGBPartNet -from utils.configuration import DataloaderConfiguration, \ - HyperparameterConfiguration, DatasetConfiguration, ModelConfiguration, \ - SystemConfiguration from utils.dataset import CASIAB, ClipConditions, ClipViews, ClipClasses from utils.sampler import TripletSampler from utils.triplet_loss import JointBatchTripletLoss, BatchTripletLoss @@ -24,9 +21,9 @@ from utils.triplet_loss import JointBatchTripletLoss, BatchTripletLoss class Model: def __init__( self, - system_config: SystemConfiguration, - model_config: ModelConfiguration, - hyperparameter_config: HyperparameterConfiguration + system_config: Dict, + model_config: Dict, + hyperparameter_config: Dict ): self.disable_acc = system_config.get('disable_acc', False) if self.disable_acc: @@ -109,11 +106,11 @@ class Model: def fit_all( self, - dataset_config: DatasetConfiguration, + dataset_config: Dict, dataset_selectors: Dict[ str, Dict[str, Union[ClipClasses, ClipConditions, ClipViews]] ], - dataloader_config: DataloaderConfiguration, + dataloader_config: Dict, ): for (curr_iter, total_iter, (condition, selector)) in zip( self.curr_iters, self.total_iters, dataset_selectors.items() @@ -135,8 +132,8 @@ class Model: def fit( self, - dataset_config: DatasetConfiguration, - dataloader_config: DataloaderConfiguration, + dataset_config: Dict, + dataloader_config: Dict, ): self.is_train = True dataset = self._parse_dataset_config(dataset_config) @@ -306,11 +303,11 @@ class Model: def predict_all( self, iters: Tuple[int], - dataset_config: DatasetConfiguration, + dataset_config: Dict, dataset_selectors: Dict[ str, Dict[str, Union[ClipClasses, ClipConditions, ClipViews]] ], - dataloader_config: DataloaderConfiguration, + dataloader_config: Dict, ) -> Dict[str, torch.Tensor]: # Transform data to features gallery_samples, probe_samples = self.transform( @@ -324,11 +321,11 @@ class Model: def transform( self, iters: Tuple[int], - dataset_config: DatasetConfiguration, + dataset_config: Dict, dataset_selectors: Dict[ str, Dict[str, Union[ClipClasses, ClipConditions, ClipViews]] ], - dataloader_config: DataloaderConfiguration + dataloader_config: Dict ): self.is_train = False # Split gallery and probe dataset @@ -430,7 +427,7 @@ class Model: def _load_pretrained( self, iters: Tuple[int], - dataset_config: DatasetConfiguration, + dataset_config: Dict, dataset_selectors: Dict[ str, Dict[str, Union[ClipClasses, ClipConditions, ClipViews]] ] @@ -449,8 +446,8 @@ class Model: def _split_gallery_probe( self, - dataset_config: DatasetConfiguration, - dataloader_config: DataloaderConfiguration, + dataset_config: Dict, + dataloader_config: Dict, ) -> Tuple[DataLoader, Dict[str, DataLoader]]: dataset_name = dataset_config.get('name', 'CASIA-B') if dataset_name == 'CASIA-B': @@ -500,7 +497,7 @@ class Model: def _parse_dataset_config( self, - dataset_config: DatasetConfiguration + dataset_config: Dict ) -> Union[CASIAB]: self.in_channels = dataset_config.get('num_input_channels', 3) self.in_size = dataset_config.get('frame_size', (64, 48)) @@ -520,7 +517,7 @@ class Model: def _parse_dataloader_config( self, dataset: Union[CASIAB], - dataloader_config: DataloaderConfiguration + dataloader_config: Dict ) -> DataLoader: config: Dict = dataloader_config.copy() (self.pr, self.k) = config.pop('batch_size', (8, 16)) @@ -16,7 +16,7 @@ pip3 install scikit-learn tqdm tensorboard cd /root git clone https://git.jordangong.com/jordangong/gait-recognition.git -cd gait-recognition; git checkout python3.8; cd .. +cd gait-recognition; git checkout python3.7; cd .. mkdir -p gait-recognition/data/CASIA-B-MRCNN wget https://storage.googleapis.com/gait-dataset/CASIA-B-MRCNN-SEG.tar.zst tar -I zstd -xf CASIA-B-MRCNN-SEG.tar.zst -C gait-recognition/data/CASIA-B-MRCNN diff --git a/utils/configuration.py b/utils/configuration.py deleted file mode 100644 index cf667ed..0000000 --- a/utils/configuration.py +++ /dev/null @@ -1,95 +0,0 @@ -from typing import TypedDict, Optional, Union, Tuple, Dict - -from utils.dataset import ClipClasses, ClipConditions, ClipViews - - -class SystemConfiguration(TypedDict): - disable_acc: bool - CUDA_VISIBLE_DEVICES: str - save_dir: str - image_log_on: bool - - -class DatasetConfiguration(TypedDict): - name: str - root_dir: str - train_size: int - num_sampled_frames: int - truncate_threshold: int - discard_threshold: int - selector: Optional[Dict[str, Union[ClipClasses, ClipConditions, ClipViews]]] - num_input_channels: int - frame_size: Tuple[int, int] - cache_on: bool - - -class DataloaderConfiguration(TypedDict): - batch_size: Tuple[int, int] - num_workers: int - pin_memory: bool - - -class ModelHPConfiguration(TypedDict): - ae_feature_channels: int - f_a_c_p_dims: Tuple[int, int, int] - hpm_scales: Tuple[int, ...] - hpm_use_1x1conv: bool - hpm_use_avg_pool: bool - hpm_use_max_pool: bool - fpfe_feature_channels: int - fpfe_kernel_sizes: Tuple[Tuple, ...] - fpfe_paddings: Tuple[Tuple, ...] - fpfe_halving: Tuple[int, ...] - tfa_squeeze_ratio: int - tfa_num_parts: int - embedding_dims: int - triplet_is_hard: bool - triplet_margins: Tuple[float, float] - - -class SubOptimizerHPConfiguration(TypedDict): - lr: int - betas: Tuple[float, float] - eps: float - weight_decay: float - amsgrad: bool - - -class OptimizerHPConfiguration(TypedDict): - start_iter: int - lr: int - betas: Tuple[float, float] - eps: float - weight_decay: float - amsgrad: bool - auto_encoder: SubOptimizerHPConfiguration - part_net: SubOptimizerHPConfiguration - hpm: SubOptimizerHPConfiguration - fc: SubOptimizerHPConfiguration - - -class SchedulerHPConfiguration(TypedDict): - step_size: int - gamma: float - - -class HyperparameterConfiguration(TypedDict): - model: ModelHPConfiguration - optimizer: OptimizerHPConfiguration - scheduler: SchedulerHPConfiguration - - -class ModelConfiguration(TypedDict): - name: str - restore_iter: int - total_iter: int - restore_iters: Tuple[int, ...] - total_iters: Tuple[int, ...] - - -class Configuration(TypedDict): - system: SystemConfiguration - dataset: DatasetConfiguration - dataloader: DataloaderConfiguration - hyperparameter: HyperparameterConfiguration - model: ModelConfiguration diff --git a/utils/misc.py b/utils/misc.py index b850830..c047618 100644 --- a/utils/misc.py +++ b/utils/misc.py @@ -1,9 +1,8 @@ import os +from typing import Dict -from utils.configuration import SystemConfiguration - -def set_visible_cuda(config: SystemConfiguration): +def set_visible_cuda(config: Dict): """Set environment variable CUDA device(s)""" CUDA_VISIBLE_DEVICES = config.get('CUDA_VISIBLE_DEVICES', None) if CUDA_VISIBLE_DEVICES: |