add TestDataset to datasets.py
This commit is contained in:
1 parent
2c7c2158c4
commit
8b2258a63c
2 files changed
+32
-1
No files matched your search
@@ -0,0 +1,21 @@
|
||||
from torch.utils.data import Dataset
|
||||
from PIL import Image
|
||||
import os
|
||||
|
||||
|
||||
class TestDataset(Dataset):
|
||||
|
||||
def __init__(self, img_dir, transform):
|
||||
self.transform = transform
|
||||
self.images = [os.path.join(img_dir, fname) for fname in os.listdir(img_dir)]
|
||||
|
||||
def __getitem__(self, idx):
|
||||
image = Image.open(self.images[idx]).convert("RGB")
|
||||
|
||||
if self.transform is not None:
|
||||
image = self.transform(image)
|
||||
|
||||
return image
|
||||
|
||||
def __len__(self):
|
||||
return len(self.images)
|
||||
+11
-1
@@ -5,11 +5,12 @@ from train import load_config
|
||||
import torch
|
||||
|
||||
|
||||
def predict():
|
||||
# load config
|
||||
config = load_config()
|
||||
|
||||
# load model from checkpoint
|
||||
pretrained_model = LitModel.load_from_checkpoint("example.ckpt", config=config)
|
||||
pretrained_model = LitModel.load_from_checkpoint("example.ckpt", config=config["hparams"])
|
||||
pretrained_model.eval()
|
||||
|
||||
# load data
|
||||
@@ -22,3 +23,12 @@ img = img.reshape((1, *img.size())) # reshape to form batch of size 1
|
||||
# inference
|
||||
output = pretrained_model(img)
|
||||
print(output)
|
||||
|
||||
|
||||
def download_from_wanb():
|
||||
MODEL_PATH = ""
|
||||
CODE_PATH = ""
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
predict()
|
||||
Reference in new issue
Block a user