Merge pull request #20 from kinoai/dev

Dev
This commit is contained in:
hobogalaxy authored and GitHub committed 2020-11-21 04:54:25 +01:00
commit e5a1b90c15
4 files changed
+58 -12

No files matched your search

+47
View File
@@ -99,6 +99,53 @@ Installation command generator: https://pytorch.org/get-started/locally/
<br> <br>
## [config.yaml](project/config.yaml) parameters explanation:
```
num_of_gpus: -1 <- -1 means use all gpus available on your machine, 0 means train on cpu
hparams: <- you can add any parameters here and then acces them in your network model or datamodule
max_epochs: 3
batch_size: 64
lr: 0.001
weight_decay: 0.000001 <- L2 normalization set in optimizer
gradient_clip_val: 0.5 <- gradient clipping value (0 means don’t clip), helps with exploding gradient issues
accumulate_grad_batches: 1 <- perform optimisation after accumulating gradient from n batches
resume:
resume_from_ckpt: False <- set to True if you want to resume
wandb_run_id: "8uuomodb" <- id of wandb run
ckpt_path: "epoch=2.ckpt" <- lightning checkpoint path
loggers:
wandb:
project: "hackathon_template_test" <- wandb project name
team: "kino" <- entity name (your username or team name you belong to)
group: None
job_type: "train"
tags: []
log_model: True <- True if you want to automatically upload your model to wandb at the end of training
offline: False <- True if you don't want to send any data to wandb server
callbacks:
checkpoint:
monitor: "val_acc" <- name of the logged metric that determines when ckpt is saved
save_top_k: 1 <- save k best models (determined by above metric)
save_last: True <- additionaly always save model from last epoch
mode: "max" # "min" <- save models with best minimum or maximum metrics score
early_stop:
monitor: "val_acc" <- name of the logged metric that determines when training is stopped
patience: 100 <- for how long metric needs to not improve in order to stop training
mode: "max" # "min"
printing:
progress_bar_refresh_rate: 5 <- refresh rate of training bar in terminal
weights_summary: "top" # "full" <- print summary of model an the beginning of the run
profiler: False <- True will print mean execution time of all methods at the end of the training
```
<br>
## Useful tips ## Useful tips
- Useful pl.Trainer() parameters: - Useful pl.Trainer() parameters:
- <b>gpus=-1</b> - use all gpus available on your machine - <b>gpus=-1</b> - use all gpus available on your machine
+9 -5
View File
@@ -1,19 +1,23 @@
num_of_gpus: -1 num_of_gpus: -1
hparams: hparams:
# these hyperparameters should always be in this file
max_epochs: 3 max_epochs: 3
batch_size: 64 batch_size: 64
lr: 0.001 lr: 0.001
accumulate_grad_batches: 1
gradient_clip_val: 0.5
output_size: 10
weight_decay: 0.000001 weight_decay: 0.000001
split_ratio: 0.9 gradient_clip_val: 0.5
accumulate_grad_batches: 1
# these hyperparameters are custom, you can add here anything
train_val_split_ratio: 0.9
output_size: 10
lin1_size: 256 lin1_size: 256
lin2_size: 256 lin2_size: 256
lin3_size: 128 lin3_size: 128
resume:
resume: # this is for resuming training from lightning checkpoint
resume_from_ckpt: False resume_from_ckpt: False
wandb_run_id: "8uuomodb" wandb_run_id: "8uuomodb"
ckpt_path: "checkpoints/epoch=2.ckpt" ckpt_path: "checkpoints/epoch=2.ckpt"
+1 -1
View File
@@ -13,7 +13,7 @@ def train(config):
# Init data module # Init data module
datamodule = MNISTDataModule( datamodule = MNISTDataModule(
batch_size=config["hparams"]["batch_size"], batch_size=config["hparams"]["batch_size"],
split_ratio=config["hparams"]["split_ratio"] split_ratio=config["hparams"]["train_val_split_ratio"]
) )
datamodule.prepare_data() datamodule.prepare_data()
datamodule.setup() datamodule.setup()
@@ -33,8 +33,6 @@ class LitModel(pl.LightningModule):
acc = accuracy_score(preds, y) acc = accuracy_score(preds, y)
self.log('train_loss', loss, on_step=False, on_epoch=True, logger=True, prog_bar=True) self.log('train_loss', loss, on_step=False, on_epoch=True, logger=True, prog_bar=True)
self.log('train_acc', acc, on_step=False, on_epoch=True, logger=True, prog_bar=True) self.log('train_acc', acc, on_step=False, on_epoch=True, logger=True, prog_bar=True)
# f1 = f1_score(preds, y, average="micro")
# self.log('train_f1', f1, on_step=False, on_epoch=True, logger=True, prog_bar=True)
return loss return loss
@@ -50,9 +48,8 @@ class LitModel(pl.LightningModule):
acc = accuracy_score(preds, y) acc = accuracy_score(preds, y)
self.log('val_loss', loss, on_step=False, on_epoch=True, logger=True, prog_bar=True) self.log('val_loss', loss, on_step=False, on_epoch=True, logger=True, prog_bar=True)
self.log('val_acc', acc, on_step=False, on_epoch=True, logger=True, prog_bar=True) self.log('val_acc', acc, on_step=False, on_epoch=True, logger=True, prog_bar=True)
# f1 = f1_score(preds, y, average="micro")
# self.log('val_f1', f1, on_step=False, on_epoch=True, logger=True, prog_bar=True)
# we can return here anything and then read it in some callback
return preds, y return preds, y
# logic for a single testing step # logic for a single testing step
@@ -67,8 +64,6 @@ class LitModel(pl.LightningModule):
acc = accuracy_score(preds, y) acc = accuracy_score(preds, y)
self.log('test_loss', loss, on_step=False, on_epoch=True, logger=True, prog_bar=True) self.log('test_loss', loss, on_step=False, on_epoch=True, logger=True, prog_bar=True)
self.log('test_acc', acc, on_step=False, on_epoch=True, logger=True, prog_bar=True) self.log('test_acc', acc, on_step=False, on_epoch=True, logger=True, prog_bar=True)
# f1 = f1_score(preds, y, average="micro")
# self.log('test_f1', f1, on_step=False, on_epoch=True, logger=True, prog_bar=True)
return loss return loss