From 57220ee45c23ac6f635a0702f93dcd21a887aa13 Mon Sep 17 00:00:00 2001 From: sushmanthreddy Date: Sat, 16 Mar 2024 23:15:03 +0530 Subject: [PATCH 1/2] added the imageio instead of opencv --- torch_dreams/custom_image_param.py | 8 +++++--- torch_dreams/masked_image_param.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/torch_dreams/custom_image_param.py b/torch_dreams/custom_image_param.py index a1c2407..6d429de 100644 --- a/torch_dreams/custom_image_param.py +++ b/torch_dreams/custom_image_param.py @@ -1,7 +1,8 @@ from .auto_image_param import BaseImageParam -import cv2 + import torch +import imageio from .utils import ( lucid_colorspace_to_rgb, @@ -42,9 +43,10 @@ def __init__(self, image, device): super().__init__() self.device = device + #use imageio to read the image if isinstance(image, str): - image = cv2.cvtColor(cv2.imread(image), cv2.COLOR_BGR2RGB)/255. - image = torch.tensor(image).permute(-1,0,1).unsqueeze(0) + image = imageio.imread(image) / 255.0 + image = torch.tensor(image).permute(2, 0, 1).unsqueeze(0) self.set_param(image) def normalize(self,x, device): diff --git a/torch_dreams/masked_image_param.py b/torch_dreams/masked_image_param.py index f554c9c..6be5725 100644 --- a/torch_dreams/masked_image_param.py +++ b/torch_dreams/masked_image_param.py @@ -1,4 +1,4 @@ -import cv2 +import imageio import torch from .custom_image_param import CustomImageParam from .transforms import imagenet_transform @@ -48,8 +48,8 @@ def __init__(self, mask_tensor, image=None, device="cuda"): self.mask = mask_tensor.to(self.device) if isinstance(image, str): - image = cv2.cvtColor(cv2.imread(image), cv2.COLOR_BGR2RGB) / 255.0 - image = torch.tensor(image).permute(-1, 0, 1).unsqueeze(0) + image = imageio.imread(image) / 255.0 + image = torch.tensor(image).permute(2, 0, 1).unsqueeze(0) self.original_nchw_image_tensor = image.to(device) From 0876aa772095bb6f29910e3b69515f78e31ea212 Mon Sep 17 00:00:00 2001 From: sushmanthreddy Date: Sat, 16 Mar 2024 23:25:46 +0530 Subject: [PATCH 2/2] added in requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4ab2ed3..40850f9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ torch>=1.8.0 torchvision>=0.8.1 -opencv-python +imageio numpy tqdm mkl