big refactoring

This commit is contained in:
hobogalaxy committed 2020-11-21 03:54:38 +01:00
1 parent cfc298a2d2
commit 53e063ca7e
10 files changed
+41 -12

No files matched your search

@@ -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
View File
@@ -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
View File
@@ -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 *
+1 -1
View File
@@ -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",
+1 -1
View File
@@ -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__()
self.save_hyperparameters(hparams)
if hparams:
self.save_hyperparameters(hparams)
self.model = SimpleLinearMNIST(config=self.hparams)
def forward(self, x):
+2 -1
View File
@@ -13,7 +13,8 @@ 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(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),