Skip to content

Commit

Permalink
(close #56) Merge pull request #59 from sushmanthreddy/opencv
Browse files Browse the repository at this point in the history
use imageio instead of opencv
  • Loading branch information
Mayukhdeb authored Mar 25, 2024
2 parents df90177 + 0876aa7 commit bfb1696
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
torch>=1.8.0
torchvision>=0.8.1
opencv-python
imageio
numpy
tqdm
mkl
8 changes: 5 additions & 3 deletions torch_dreams/custom_image_param.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .auto_image_param import BaseImageParam

import cv2

import torch
import imageio

from .utils import (
lucid_colorspace_to_rgb,
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions torch_dreams/masked_image_param.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cv2
import imageio
import torch
from .custom_image_param import CustomImageParam
from .transforms import imagenet_transform
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit bfb1696

Please sign in to comment.