This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
next(iter(image_dataset)).shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image_dataset = ImageDataset( | |
img_dir=os.environ["IMG_DIR"], | |
transform=preprocess | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
next(iter(image_dataset)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image_dataset = ImageDataset(img_dir=os.environ["IMG_DIR"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import glob | |
from torch.utils.data import Dataset | |
class ImageDataset(Dataset): | |
def __init__(self, img_dir, transform=None): | |
self.img_dir = img_dir | |
self.image_file_names = glob.glob(os.path.join(img_dir, "*.jpg")) | |
self.transform = transform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with torch.no_grad(): | |
image_features = model.encode_image( | |
processed_images[0].unsqueeze(0) | |
) | |
image_features.shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with torch.no_grad(): | |
image_features = model.encode_image(image_input).float() | |
image_features.shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import torch | |
device = 'cuda' if torch.cuda.is_available() else 'cpu' | |
image_input = torch.tensor(np.stack(processed_images)).to(device) | |
image_input.shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torchvision.transforms import ToPILImage | |
plot_pil_images([ToPILImage()(x) for x in processed_images]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
processed_images = [preprocess.transforms[4](image) for image in processed_images] |