Exemplo n.º 1
0
 def __getitem__(self, index):
     image = read_image(self.file_paths[index])
     if len(image.shape) < 3:
         image = image[..., np.newaxis]
     image = torch.Tensor(image.transpose(2, 0, 1))
     if self.has_target:
         return image, self.target[index]
     return image
Exemplo n.º 2
0
 def __getitem__(self, index):
     image = read_image(self.file_paths[index])
     if len(image.shape) < 3:
         image = image[..., np.newaxis]
     image = torch.Tensor(image.transpose(2, 0, 1))
     if self.has_target:
         return image, self.target[index]
     return image
Exemplo n.º 3
0
def _image_to_array(img_path):
    """Read the image from the path and return image object.
        Return an image object.

    Args:
        img_path: image file name in images_dir_path.
    """
    if os.path.exists(img_path):
        img = read_image(img_path)
        if len(img.shape) < 3:
            img = img[..., np.newaxis]
        return img
    else:
        raise ValueError("%s image does not exist" % img_path)
Exemplo n.º 4
0
def _image_to_array(img_path):
    """Read the image from the path and return it as an numpy.ndarray.
    
    Load the image file as an array
    
    Args:
        img_path: a string whose value is the image file name
    """
    if os.path.exists(img_path):
        img = read_image(img_path)
        if len(img.shape) < 3:
            img = img[..., np.newaxis]
        return img
    else:
        raise ValueError("%s image does not exist" % img_path)
Exemplo n.º 5
0
def read_images(img_file_names, images_dir_path):
    """Read the images from the path and return their numpy.ndarray instance.
        Return a numpy.ndarray instance containing the training data.

    Args:
        img_file_names: List containing images names.
        images_dir_path: Path to the directory containing images.
    """
    x_train = []
    if os.path.isdir(images_dir_path):
        for img_file in img_file_names:
            img_path = os.path.join(images_dir_path, img_file)
            if os.path.exists(img_path):
                img = read_image(img_path)
                if len(img.shape) < 3:
                    img = img[..., np.newaxis]
                x_train.append(img)
            else:
                raise ValueError("%s image does not exist" % img_file)
    else:
        raise ValueError("Directory containing images does not exist")
    return np.asanyarray(x_train)
Exemplo n.º 6
0
def read_images(img_file_names, images_dir_path):
    """Read the images from the path and return their numpy.ndarray instance.
        Return a numpy.ndarray instance containing the training data.

    Args:
        img_file_names: List containing images names.
        images_dir_path: Path to the directory containing images.
    """
    x_train = []
    if os.path.isdir(images_dir_path):
        for img_file in img_file_names:
            img_path = os.path.join(images_dir_path, img_file)
            if os.path.exists(img_path):
                img = read_image(img_path)
                if len(img.shape) < 3:
                    img = img[..., np.newaxis]
                x_train.append(img)
            else:
                raise ValueError("%s image does not exist" % img_file)
    else:
        raise ValueError("Directory containing images does not exist")
    return np.asanyarray(x_train)