start introduction of Hydra for config management
This commit is contained in:
1 parent
99ac2a9062
commit
2726557906
19 files changed
+203
-127
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# pytorch lightning imports
|
||||
from pytorch_lightning.loggers import WandbLogger
|
||||
from pytorch_lightning.loggers import WandbLogger, CometLogger
|
||||
from pytorch_lightning.profiler import SimpleProfiler
|
||||
import pytorch_lightning as pl
|
||||
|
||||
@@ -287,3 +287,11 @@ def init_tensorboard_logger() -> pl.loggers.TensorBoardLogger:
|
||||
"""Initialize tensorboard logger"""
|
||||
# TODO
|
||||
return None
|
||||
|
||||
|
||||
def init_comet_logger(project_config: dict,
|
||||
run_config: dict,
|
||||
model: pl.LightningModule,
|
||||
datamodule: pl.LightningDataModule) -> pl.loggers.CometLogger:
|
||||
|
||||
comet_logger = CometLogger()
|
||||
@@ -0,0 +1,39 @@
|
||||
from pytorch_modules.lightning_datamodules.mnist_datamodule import transforms
|
||||
from PIL import Image
|
||||
|
||||
# the LitModel you import should be the same as the one you used for training!
|
||||
from pytorch_modules.lightning_models.simple_mnist_classifier import LitModel
|
||||
|
||||
|
||||
def predict():
|
||||
"""
|
||||
This method is example of inference with a trained model.
|
||||
It Loads trained image classification model from checkpoint.
|
||||
Then it loads example image and predicts its label.
|
||||
Model used in simple_mnist_classifier.py should be the same as during training!!!
|
||||
"""
|
||||
|
||||
CKPT_PATH = "epoch=0.ckpt"
|
||||
|
||||
# load model from checkpoint
|
||||
trained_model = LitModel.load_from_checkpoint(checkpoint_path=CKPT_PATH)
|
||||
|
||||
# switch to evaluation mode
|
||||
trained_model.eval()
|
||||
trained_model.freeze()
|
||||
|
||||
# load data
|
||||
img = Image.open("data/example_img.png").convert("L") # for monochromatic conversion
|
||||
# img = Image.open("data/example_img.png").convert("RGB") # for RGB conversion
|
||||
|
||||
# preprocess
|
||||
img = transforms.mnist_test_transforms(img)
|
||||
img = img.reshape((1, *img.size())) # reshape to form batch of size 1
|
||||
|
||||
# inference
|
||||
output = trained_model(img)
|
||||
print(output)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
predict()
|
||||
Reference in new issue
Block a user