Skip to content

Commit

Permalink
no improvement in new module
Browse files Browse the repository at this point in the history
  • Loading branch information
ruhyadi committed Sep 6, 2022
1 parent 1b2f878 commit c08555d
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 25 deletions.
12 changes: 7 additions & 5 deletions .hydra/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ test: false
ckpt_path: null
seed: 420
datamodule:
_target_: src.datamodules.kitti_datamodule.KITTIDataModule2
_target_: src.datamodules.kitti_datamodule.KITTIDataModule3
dataset_path: ${paths.data_dir}
train_sets: ${paths.data_dir}/train_80.txt
val_sets: ${paths.data_dir}/val_80.txt
test_sets: ${paths.data_dir}/test_80.txt
batch_size: 128
num_worker: 32
model:
_target_: src.models.regressor.RegressorModel2
_target_: src.models.regressor.RegressorModel3
net:
_target_: src.models.components.base.RegressorNet2
_target_: src.models.components.base.RegressorNet
backbone:
_target_: torchvision.models.resnet18
pretrained: true
bins: 2
lr: 0.0001
lr: 0.001
momentum: 0.9
w: 0.4
alpha: 0.6
Expand Down Expand Up @@ -101,4 +101,6 @@ extras:
ignore_warnings: false
enforce_tags: true
print_config: true
name: new_network_&_dataset
wandb:
name: model3
name: model3
10 changes: 5 additions & 5 deletions .hydra/hydra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ hydra:
- hydra.job.name=train_ddp_process_3
- hydra.mode=RUN
task:
- experiment=model2
- experiment=model3
job:
name: train_ddp_process_3
chdir: null
override_dirname: experiment=model2
override_dirname: experiment=model3
id: ???
num: ???
config_name: train.yaml
Expand Down Expand Up @@ -163,15 +163,15 @@ hydra:
debug: null
local: default.yaml
hparams_search: null
experiment: model2
experiment: model3
hydra: default.yaml
extras: default.yaml
paths: default.yaml
trainer: dgx.yaml
logger: wandb.yaml
callbacks: default.yaml
model: regressor2.yaml
datamodule: kitti_datamodule2.yaml
model: regressor3.yaml
datamodule: kitti_datamodule3.yaml
hydra/env: default
hydra/callbacks: null
hydra/job_logging: colorlog
Expand Down
2 changes: 1 addition & 1 deletion .hydra/overrides.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- experiment=model2
- experiment=model3
4 changes: 2 additions & 2 deletions configs/convert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ignore_warnings: True
root: ${hydra:runtime.cwd}

# checkpoint directory
checkpoint_dir: ${root}/logs/train/runs/2022-09-05_13-50-07/checkpoints/epoch_009.ckpt
checkpoint_dir: ${root}/logs/train/runs/2022-09-06_10-37-38/checkpoints/epoch_009.ckpt

# dump dir
dump_dir: ${root}/weights
Expand All @@ -33,4 +33,4 @@ input_sample:
convert_to: "pytorch" # [pytorch, torchscript, onnx, tensorrt]

# model name without extension
name: ${dump_dir}/regressor_resnet18_new3
name: ${dump_dir}/regressor_new_module
6 changes: 3 additions & 3 deletions configs/datamodule/kitti_datamodule.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
_target_: src.datamodules.kitti_datamodule.KITTIDataModule

dataset_path: ${paths.data_dir} # data_dir is specified in config.yaml
train_sets: ${paths.data_dir}/train.txt
val_sets: ${paths.data_dir}/val.txt
test_sets: ${paths.data_dir}/test.txt
train_sets: ${paths.data_dir}/train_80.txt
val_sets: ${paths.data_dir}/val_80.txt
test_sets: ${paths.data_dir}/test_80.txt
batch_size: 128
num_worker: 32
8 changes: 8 additions & 0 deletions configs/datamodule/kitti_datamodule3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_target_: src.datamodules.kitti_datamodule.KITTIDataModule3

dataset_path: ${paths.data_dir} # data_dir is specified in config.yaml
train_sets: ${paths.data_dir}/train_80.txt
val_sets: ${paths.data_dir}/val_80.txt
test_sets: ${paths.data_dir}/test_80.txt
batch_size: 128
num_worker: 32
11 changes: 11 additions & 0 deletions configs/datamodule/kitti_dataset3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
_target_: src.datamodules.components.kitti_dataset.KITTIDataset3

dataset_path: ${paths.data_dir}
dataset_sets: ${paths.data_dir}/train_80.txt
bins: 2
overlap: 0.1
image_size: 224
categories:
- "car"
- "pedestrian"
- "cyclist"
32 changes: 32 additions & 0 deletions configs/experiment/model3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# @package _global_

# to execute this experiment run:
# python train.py experiment=example

defaults:
- override /datamodule: kitti_datamodule3.yaml
- override /model: regressor3.yaml
- override /callbacks: default.yaml
- override /logger: wandb.yaml
- override /trainer: dgx.yaml

# all parameters below will be merged with parameters from default configurations set above
# this allows you to overwrite only specified parameters

seed: 420

trainer:
min_epochs: 1
max_epochs: 10
gpus: [0,1,2,3]
strategy: ddp

datamodule:
train_sets: ${paths.data_dir}/train_80.txt
val_sets: ${paths.data_dir}/val_80.txt

wandb:
name: "model3"

# name of the run determines folder name in logs
name: "model3"
4 changes: 2 additions & 2 deletions configs/inference.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
defaults:
- _self_
- detector: yolov5.yaml
- model: regressor2.yaml
- model: regressor.yaml
- augmentation: inference_preprocessing.yaml

# debugging config (enable through command line, e.g. `python train.py debug=default)
Expand Down Expand Up @@ -35,7 +35,7 @@ save_result: True

# regressor weights
# regressor_weights: ${root}/weights/regressor_resnet18.pt
regressor_weights: ${root}/weights/regressor_resnet18_new3.pt
regressor_weights: ${root}/weights/regressor_old1.pt

# inference type
inference_type: pytorch # [pytorch, onnx, openvino, tensorrt]
Expand Down
13 changes: 13 additions & 0 deletions configs/model/regressor3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
_target_: src.models.regressor.RegressorModel3

net:
_target_: src.models.components.base.RegressorNet
backbone:
_target_: torchvision.models.resnet18 # change model on this
pretrained: True
bins: 2

lr: 0.001
momentum: 0.9
w: 0.4
alpha: 0.6
6 changes: 3 additions & 3 deletions configs/train.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# order of defaults determines the order in which configs override each other
defaults:
- _self_
- datamodule: kitti_datamodule2.yaml
- model: regressor2.yaml
- datamodule: kitti_datamodule.yaml
- model: regressor.yaml
- callbacks: default.yaml
- logger: null # set logger here or use command line (e.g. `python train.py logger=tensorboard`)
- logger: wandb.yaml # set logger here or use command line (e.g. `python train.py logger=tensorboard`)
- trainer: dgx.yaml
- paths: default.yaml
- extras: default.yaml
Expand Down
54 changes: 51 additions & 3 deletions src/datamodules/kitti_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from torch.utils.data import DataLoader
from torchvision.transforms import transforms

from src.datamodules.components.kitti_dataset import KITTIDataset, KITTIDataLoader
from src.datamodules.components.kitti_dataset import KITTIDataset, KITTIDataset3

class KITTIDataModule(LightningDataModule):
def __init__(
Expand Down Expand Up @@ -99,6 +99,52 @@ def val_dataloader(self):
shuffle=False
)

class KITTIDataModule3(LightningDataModule):
def __init__(
self,
dataset_path: str = './data/KITTI',
train_sets: str = './data/KITTI/train.txt',
val_sets: str = './data/KITTI/val.txt',
test_sets: str = './data/KITTI/test.txt',
batch_size: int = 32,
num_worker: int = 4,
):
super().__init__()

# save hyperparameters
self.save_hyperparameters(logger=False)

# transforms
# TODO: using albumentations
self.dataset_transforms = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))
])

def setup(self, stage=None):
""" Split dataset to training and validation """
self.KITTI_train = KITTIDataset3(self.hparams.dataset_path, self.hparams.train_sets)
self.KITTI_val = KITTIDataset3(self.hparams.dataset_path, self.hparams.val_sets)
# self.KITTI_test = KITTIDataset(self.hparams.dataset_path, self.hparams.test_sets)
# TODO: add test datasets dan test sets

def train_dataloader(self):
return DataLoader(
dataset=self.KITTI_train,
batch_size=self.hparams.batch_size,
num_workers=self.hparams.num_worker,
shuffle=True
)

def val_dataloader(self):
return DataLoader(
dataset=self.KITTI_val,
batch_size=self.hparams.batch_size,
num_workers=self.hparams.num_worker,
shuffle=False
)


if __name__ == '__main__':

# dataset = KITTIDataModule(batch_size=1)
Expand All @@ -109,12 +155,14 @@ def val_dataloader(self):
# print(label)
# break

dataset = KITTIDataModule2(batch_size=1)
dataset = KITTIDataModule3(batch_size=1)
dataset.setup()
train = dataset.train_dataloader()

for img, label in train:
print(label["orientation"])
print(img.shape)
print(label)
break

# output
# torch.Size([1, 3, 224, 224])
Expand Down
Loading

0 comments on commit c08555d

Please sign in to comment.