big refactoring
This commit is contained in:
1 parent
cfc298a2d2
commit
53e063ca7e
10 files changed
+39
-10
No files matched your search
@@ -14,10 +14,10 @@ The directory structure of new project looks like this:
|
||||
│ │
|
||||
│ ├── notebooks <- Jupyter notebooks
|
||||
│ │
|
||||
│ ├── training_modules <- All modules necessary for training deep learning models
|
||||
│ ├── training_modules <- All modules useful for training deep learning models
|
||||
│ │ ├── callbacks.py <- Useful training callbacks
|
||||
│ │ ├── data_modules.py <- "LightningDataModule" modules (wrappers for PyTorch "Dataset")
|
||||
│ │ ├── datasets.py <- PyTorch "Dataset" modules
|
||||
│ │ ├── datamodules.py <- "LightningDataModule" modules (wrappers for PyTorch "Dataset")
|
||||
│ │ ├── lightning_wrapper.py <- Contains train/val/test step methods executed during training
|
||||
│ │ ├── loggers.py <- Initializers for different loggers (wandb, tensorboard, etc.)
|
||||
│ │ ├── models.py <- Neural networks declarations
|
||||
@@ -86,6 +86,8 @@ Installation command generator: https://pytorch.org/get-started/locally/
|
||||
`right click on directory -> "Mark Directory as" -> "Sources Root"`
|
||||
- set terminal emulation:<br>
|
||||
`Ctrl + Shift + A -> type "Edit Configurations..." -> select "Emulate terminal in output console"`
|
||||
- run training:<br>
|
||||
`right click on train.py file -> "Run 'train'"`
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -47,6 +47,29 @@ def download_artifact():
|
||||
print("Files are being downloaded now...")
|
||||
|
||||
|
||||
def download_model_from_wandb_run():
|
||||
"""
|
||||
WARNING: This will overwrite your training_modules/models.py and training_modules/lightning_wrapper.py files!
|
||||
"""
|
||||
RUN_ID = "kino/hackathon_template_test/lx9voyom"
|
||||
MODEL_PATH = "last.ckpt"
|
||||
CODE_PATHS = [
|
||||
"code/training_modules/lightning_wrapper.py",
|
||||
"code/training_modules/models.py"
|
||||
]
|
||||
|
||||
api = wandb.Api()
|
||||
run = api.run(path=RUN_ID)
|
||||
|
||||
# download model
|
||||
run.file(MODEL_PATH).download(replace=True)
|
||||
|
||||
# download and replace your code
|
||||
for path in CODE_PATHS:
|
||||
run.file(path).download(root="../training_modules/", replace=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
upload_artifact()
|
||||
# download_artifact()
|
||||
# download_model_from_wandb_run()
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
from training_modules.lightning_wrapper import LitModel
|
||||
from training_modules.data_modules import *
|
||||
from training_modules.datamodules import *
|
||||
from training_modules.datasets import *
|
||||
from training_modules import transforms
|
||||
from PIL import Image
|
||||
@@ -8,7 +8,8 @@ from PIL import Image
|
||||
def predict():
|
||||
"""
|
||||
Loads model from checkpoint.
|
||||
Files training_modules/models.py and training_modules/lightning_wrapper.py should be the same.
|
||||
Model used in training_modules/lightning_wrapper.py and declaration of that model in training_modules/models.py
|
||||
should be the same as during training.
|
||||
"""
|
||||
|
||||
CKPT_PATH = "epoch=0.ckpt"
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import yaml
|
||||
# custom
|
||||
from training_modules.lightning_wrapper import LitModel
|
||||
from training_modules.loggers import *
|
||||
from training_modules.data_modules import *
|
||||
from training_modules.datamodules import *
|
||||
from training_modules.callbacks import *
|
||||
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ class SaveCodeToWandbCallback(pl.Callback):
|
||||
self.wandb_save_dir = wandb_save_dir
|
||||
self.files_to_be_saved = [
|
||||
"training_modules/callbacks.py",
|
||||
"training_modules/data_modules.py",
|
||||
"training_modules/datamodules.py",
|
||||
"training_modules/datasets.py",
|
||||
"training_modules/lightning_wrapper.py",
|
||||
"training_modules/loggers.py",
|
||||
|
||||
File renamed without changes.
@@ -3,7 +3,7 @@ from PIL import Image
|
||||
import os
|
||||
|
||||
|
||||
class TestDataset(Dataset):
|
||||
class TestDatasetForImgs(Dataset):
|
||||
|
||||
def __init__(self, img_dir, transform):
|
||||
self.transform = transform
|
||||
|
||||
@@ -10,10 +10,12 @@ from training_modules.models import *
|
||||
|
||||
class LitModel(pl.LightningModule):
|
||||
|
||||
def __init__(self, hparams):
|
||||
def __init__(self, hparams=None):
|
||||
super().__init__()
|
||||
|
||||
if hparams:
|
||||
self.save_hyperparameters(hparams)
|
||||
|
||||
self.model = SimpleLinearMNIST(config=self.hparams)
|
||||
|
||||
def forward(self, x):
|
||||
|
||||
@@ -14,6 +14,7 @@ class SimpleLinearMNIST(nn.Module):
|
||||
# mnist images are (1, 28, 28) (channels, width, height)
|
||||
self.model = nn.Sequential(
|
||||
nn.Linear(28*28, config["lin1_size"]),
|
||||
# nn.Linear(3*32*32, config["lin1_size"]), # for CIFAR10
|
||||
nn.BatchNorm1d(config["lin1_size"]),
|
||||
nn.ReLU(),
|
||||
nn.Dropout(p=0.3),
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
torchvision>=0.8.1
|
||||
pytorch-lightning>=1.0.7
|
||||
pytorch-lightning-bolts>=0.2.5
|
||||
wandb>=0.10.10
|
||||
wandb>=0.10.11
|
||||
PyYAML>=5.3.1
|
||||
scikit-learn>=0.23.2
|
||||
efficientnet-pytorch>=0.7.0
|
||||
pandas>=1.1.4
|
||||
seaborn>=0.11.0
|
||||
opencv-python>=4.4.0.46
|
||||
Reference in new issue
Block a user