-
Notifications
You must be signed in to change notification settings - Fork 1
/
evaluate.py
62 lines (50 loc) · 2.09 KB
/
evaluate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import yaml
import argparse
import numpy as np
from pathlib import Path
from models import *
from experiment import VAEXperiment
import torch.backends.cudnn as cudnn
from pytorch_lightning import Trainer
from pytorch_lightning.loggers import TensorBoardLogger
from pytorch_lightning import seed_everything
from pytorch_lightning.callbacks import LearningRateMonitor, ModelCheckpoint
from f3_dataloader_lightning import VAEDataset
from pytorch_lightning.strategies import DDPStrategy
import pytorch_lightning as pl
from models import * # Assuming this includes your model classes
parser = argparse.ArgumentParser(description='Generic runner for VAE models')
parser.add_argument('--config', '-c',
dest="filename",
metavar='FILE',
help = 'path to the config file',
default='configs/cvae.yaml')
args = parser.parse_args()
with open(args.filename, 'r') as file:
try:
config = yaml.safe_load(file)
except yaml.YAMLError as exc:
print(exc)
tb_logger = TensorBoardLogger(save_dir=config['logging_params']['save_dir'],
name=config['model_params']['name'],)
# For reproducibility
seed_everything(config['exp_params']['manual_seed'], True)
model = vae_models[config['model_params']['name']](**config['model_params'])
experiment = VAEXperiment(model,
config['exp_params'])
trainer = pl.Trainer()
trainer.test(datamodule=data)
# Path to your `.ckpt` file
checkpoint_path = 'logs/ConditionalVAE/version_74/checkpoints/last.ckpt'
# Load the model
#model = vae_models[config['model_params']['name']](**config['model_params'])
#experiment = VAEXperiment(model,config['exp_params']).load_from_checkpoint(checkpoint_path)
experiment = VAEXperiment.load_from_checkpoint(checkpoint_path)
# Example: Using the model for inference
experiment.eval()
experiment.sample_one_image()
# # Assuming a dummy input tensor
# input_tensor = torch.randn((64, 1, 64, 64)) # Adjust the size based on your model's expected input
# with torch.no_grad():
# output = model(input_tensor)