finish predict.py file

This commit is contained in:
hobogalaxy committed 2020-11-21 03:39:32 +01:00
1 parent a9439b5c61
commit cfc298a2d2
1 file changed
+14 -15
+14 -15
View File
@@ -1,20 +1,27 @@
from training_modules.lightning_wrapper import LitModel from training_modules.lightning_wrapper import LitModel
from training_modules.data_modules import *
from training_modules.datasets import *
from training_modules import transforms from training_modules import transforms
import pytorch_lightning as pl from PIL import Image
from train import load_config
import torch
def predict(): def predict():
# load config """
config = load_config() Loads model from checkpoint.
Files training_modules/models.py and training_modules/lightning_wrapper.py should be the same.
"""
CKPT_PATH = "epoch=0.ckpt"
# load model from checkpoint # load model from checkpoint
pretrained_model = LitModel.load_from_checkpoint("example.ckpt", hparams=config["hparams"]) pretrained_model = LitModel.load_from_checkpoint(checkpoint_path=CKPT_PATH)
# switch to evaluation mode
pretrained_model.eval() pretrained_model.eval()
pretrained_model.freeze()
# load data # load data
img = None img = Image.open("example_img.png").convert("RGB")
# preprocess # preprocess
img = transforms.efficient_net_test_preprocess(img) img = transforms.efficient_net_test_preprocess(img)
@@ -25,13 +32,5 @@ def predict():
print(output) print(output)
def download_from_wandb():
"""
WARNING: This will overwrite your models.py, lightning_wrapper.py and config.yaml files!
"""
MODEL_PATH = ""
CODE_PATH = ""
if __name__ == "__main__": if __name__ == "__main__":
predict() predict()