Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test function #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import numpy as np
import torchvision.transforms.functional as F
from torch.utils.data import DataLoader
from imageio import imread
from PIL import Image
from scipy.misc import imread
from skimage.feature import canny
from skimage.color import rgb2gray, gray2rgb
from .utils import create_mask
Expand Down Expand Up @@ -54,7 +54,7 @@ def load_item(self, index):
size = self.input_size

# load image
img = imread(self.data[index])
img = imread(self.data[index])[:,:,:3]

# gray to rgb
if len(img.shape) < 3:
Expand Down Expand Up @@ -87,7 +87,7 @@ def load_edge(self, img, index, mask):

# in test mode images are masked (with masked regions),
# using 'mask' parameter prevents canny to detect edges for the masked regions
mask = None if self.training else (1 - mask / 255).astype(np.bool)
mask = None if self.training else (1 - mask / 255).astype(bool)

# canny
if self.edge == 1:
Expand All @@ -99,12 +99,12 @@ def load_edge(self, img, index, mask):
if sigma == 0:
sigma = random.randint(1, 4)

return canny(img, sigma=sigma, mask=mask).astype(np.float)
return canny(img, sigma=sigma, mask=mask).astype(float)

# external
else:
imgh, imgw = img.shape[0:2]
edge = imread(self.edge_data[index])
edge = imread(self.edge_data[index])[:,:,:3]
edge = self.resize(edge, imgh, imgw)

# non-max suppression
Expand Down Expand Up @@ -137,7 +137,7 @@ def load_mask(self, img, index):
# external
if mask_type == 3:
mask_index = random.randint(0, len(self.mask_data) - 1)
mask = imread(self.mask_data[mask_index])
mask = imread(self.mask_data[mask_index])[:,:,:3]
mask = self.resize(mask, imgh, imgw)
mask = (mask > 0).astype(np.uint8) * 255 # threshold due to interpolation
return mask
Expand All @@ -146,7 +146,8 @@ def load_mask(self, img, index):
if mask_type == 6:
mask = imread(self.mask_data[index])
mask = self.resize(mask, imgh, imgw, centerCrop=False)
mask = rgb2gray(mask)
if mask.shape[-1] == 3:
mask = rgb2gray(mask)
mask = (mask > 0).astype(np.uint8) * 255
return mask

Expand All @@ -165,7 +166,7 @@ def resize(self, img, height, width, centerCrop=True):
i = (imgw - side) // 2
img = img[j:j + side, i:i + side, ...]

img = scipy.misc.imresize(img, [height, width])
img = np.array(Image.fromarray(img).resize((width, height)))

return img

Expand Down