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

Change some mechanism #14

Merged
merged 18 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ python train.py -c pipeline.yaml
```
python train.py \
-c pipeline.yaml \
-o trainer.args.num_epochs=50 \
-o trainer.args.num_iterations=5000 \
global.resume=checkpoint.pth
```
**Notice: There are no spaces between keys and values in -o flag**
Expand Down
95 changes: 44 additions & 51 deletions configs/classification/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,94 +1,87 @@
global:
debug: True
debug: true
cfg_transform: configs/classification/transform.yaml
save_dir: runs
save_dir: /content/main/runs
device: cuda:0
use_fp16: True
use_fp16: true
pretrained: null
resume: null


trainer:
name: ClassificationTrainer
args:
num_epochs: 100
total_accumulate_steps: null
num_iterations: 10000
clip_grad: 10.0
print_per_iter: 20
save_per_iter: 1000
evaluate_per_epoch : 1
print_interval: 20
save_interval: 1000
evaluate_interval : 1
visualize_when_val : True


model:
name: BaseTimmModel
args:
name: convnext_small
from_pretrained: True
from_pretrained: true
num_classes: 2


loss:
name: SmoothCELoss
args:
smoothing: 0.1

name: CELoss
metrics:
- name: Accuracy
args:
- name: BalancedAccuracyMetric
args:
- name: F1ScoreMetric
args:
average: weighted
- name: ConfusionMatrix
args:
- name: ErrorCases
args:

- name: Accuracy
args: null
- name: BalancedAccuracyMetric
args: null
- name: F1ScoreMetric
args:
average: weighted
- name: ConfusionMatrix
args: null
- name: ErrorCases
args:
optimizer:
name: AdamW
args:
lr: 0.001 # [adam: 1e-3 | sgd: 1e-2]
lr: 0.001
weight_decay: 0.0005
betas: [0.937, 0.999]

betas:
- 0.937
- 0.999
scheduler:
name: SchedulerWrapper
args:
scheduler_name: cosine2
t_initial: 7
t_mul: 0.9
eta_mul: 0.9
eta_min: 0.000001


data:
eta_min: 1.0e-06
data:
dataset:
train:
name: ImageFolderDataset
args:
image_dir: data/dog-vs-cats/train
image_dir: /content/main/data/dog-vs-cats/train
txt_classnames: configs/classification/classes.txt
test: False

val:
name: ImageFolderDataset
args:
image_dir: data/dog-vs-cats/val
image_dir: /content/main/data/dog-vs-cats/val
txt_classnames: configs/classification/classes.txt
test: True

dataloader:
train:
name: BalanceSampler
name: DataLoaderWithCollator
args:
batch_size: 64
drop_last: True
shuffle: False
batch_size: 32
drop_last: true
shuffle: false
collate_fn:
name: MixupCutmixCollator
args:
mixup_alpha: 0.4
cutmix_alpha: 1.0
weight: [0.2, 0.2]
sampler:
name: BalanceSampler
args:
val:
name: DataLoaderWithCollator
args:
batch_size: 64
drop_last: False
shuffle: True
batch_size: 32
drop_last: false
shuffle: true
2 changes: 1 addition & 1 deletion configs/segmentation/eval.py → configs/semantic/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mpl.use("Agg")
from theseus.opt import Opts
from theseus.segmentation.pipeline import Pipeline
from theseus.semantic.pipeline import Pipeline

if __name__ == "__main__":
opts = Opts().parse_args()
Expand Down
8 changes: 4 additions & 4 deletions configs/segmentation/infer.py → configs/semantic/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
import torch
from datetime import datetime
from theseus.opt import Config
from theseus.segmentation.models import MODEL_REGISTRY
from theseus.segmentation.augmentations import TRANSFORM_REGISTRY
from theseus.segmentation.datasets import DATASET_REGISTRY, DATALOADER_REGISTRY
from theseus.semantic.models import MODEL_REGISTRY
from theseus.semantic.augmentations import TRANSFORM_REGISTRY
from theseus.semantic.datasets import DATASET_REGISTRY, DATALOADER_REGISTRY

from theseus.utilities.loading import load_state_dict
from theseus.utilities.loggers import LoggerObserver, StdoutLogger
from theseus.utilities.cuda import get_devices_info
from theseus.utilities.getter import (get_instance, get_instance_recursively)

from theseus.utilities.visualization.visualizer import Visualizer
from theseus.segmentation.datasets.csv_dataset import CSVDataset
from theseus.semantic.datasets.csv_dataset import CSVDataset

@DATASET_REGISTRY.register()
class TestCSVDataset(CSVDataset):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
global:
debug: true
cfg_transform: configs/segmentation/transform.yaml
cfg_transform: configs/semantic/transform.yaml
save_dir: runs
device: cuda:0
use_fp16: true
pretrained: null
resume: null
trainer:
name: SegmentationTrainer
name: SemanticTrainer
args:
num_epochs: 50
total_accumulate_steps: null
num_iterations: 50000
clip_grad: 10.0
print_per_iter: 20
save_per_iter: 1000
evaluate_per_epoch: 1
print_interval: 20
save_interval: 1000
evaluate_interval: 1
visualize_when_val: true
model:
name: BaseSegModel
Expand Down Expand Up @@ -61,7 +60,7 @@ data:
image_dir: data/images/train
mask_dir: data/masks/train
csv_path: data/train.csv
txt_classnames: configs/segmentation/classes.txt
txt_classnames: configs/semantic/classes.txt
mosaic_size: 960
mosaic_prob: 0.4
val:
Expand All @@ -70,7 +69,7 @@ data:
image_dir: data/images/val
mask_dir: data/masks/val
csv_path: data/val.csv
txt_classnames: configs/segmentation/classes.txt
txt_classnames: configs/semantic/classes.txt
dataloader:
train:
name: DataLoaderWithCollator
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mpl.use("Agg")
from theseus.opt import Opts
from theseus.segmentation.pipeline import Pipeline
from theseus.semantic.pipeline import Pipeline

if __name__ == "__main__":
opts = Opts().parse_args()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ train:
# value: 0
- name: AlbNormalize
args:
mean: [0.229, 0.224, 0.225]
std: [0.485, 0.456, 0.406]
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
- name: AlbToTensorV2
val:
name: AlbCompose
Expand All @@ -40,6 +40,6 @@ val:
height: 640
- name: AlbNormalize
args:
mean: [0.229, 0.224, 0.225]
std: [0.485, 0.456, 0.406]
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
- name: AlbToTensorV2
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
albumentations
albumentations>=1.1.0
pyyaml>=5.1
webcolors
tensorboard
tqdm
ensemble-boxes
timm
timm>=0.5.4
omegaconf
pycocotools
gdown==4.3.0
gdown>=4.4.0
grad-cam
tabulate
segmentation-models-pytorch
opencv-python-headless==4.1.2.30
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
"omegaconf",
"gdown==3.13.0",
"grad-cam",
"tabulate",
"segmentation-models-pytorch"
],
)
4 changes: 3 additions & 1 deletion theseus/base/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from torch.utils.data import DataLoader, Dataset
from .dataloader import DataLoaderWithCollator
from .dataset import ChainDataset, ConcatDataset, ImageDataset
from .balance_sampler import BalanceSampler
from .sampler import BalanceSampler
from .collator import ChainCollatorWrapper

DATASET_REGISTRY = Registry('DATASET')
DATASET_REGISTRY.register(Dataset)
Expand All @@ -13,4 +14,5 @@
DATALOADER_REGISTRY = Registry('DATALOADER')
DATALOADER_REGISTRY.register(DataLoader)
DATALOADER_REGISTRY.register(BalanceSampler)
DATALOADER_REGISTRY.register(ChainCollatorWrapper)
DATALOADER_REGISTRY.register(DataLoaderWithCollator)
52 changes: 0 additions & 52 deletions theseus/base/datasets/balance_sampler.py

This file was deleted.

21 changes: 21 additions & 0 deletions theseus/base/datasets/collator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import List

class BaseCollator(object):
"""Base collator function
"""
def __init__(self, **kwargs) -> None:
pass

def __call__(self, batch):
return batch

class ChainCollatorWrapper(BaseCollator):
"""Wrapper for list of collate functions
"""
def __init__(self, pre_collate_fns: List, **kwargs):
self.pre_collate_fns = pre_collate_fns

def __call__(self, batch):
for fn in self.pre_collate_fns:
batch = fn(batch)
return batch
Loading