I’m beginner for Pytorch. I want to increase the number of datasets (data augmentation).
In this case, I have one image of cat and I want to use
albumentations to increase the number of images and save image into another folder as follows:
import cv2 import torch import albumentations as A import numpy as np import matplotlib.pyplot as plt from torchvision.utils import save_image
I define an augmentation as follows:
LOADER_TRANSFORMED = A.Compose([ A.HorizontalFlip(p=0.6), A.RandomBrightnessContrast(brightness_limit=1, contrast_limit=1, p=0.4) ])
OpenCV to read an image and convert it to the RGB colorspace.
IMAGE = cv2.imread('/content/drive/MyDrive/Test/cat.jpg') # default BGR IMAGE = cv2.cvtColor(IMAGE, cv2.COLOR_BGR2RGB) # BGR -> RGB
Augment an image as follows:
TRANSFORMED = LOADER_TRANSFORMED(image=IMAGE) # dict TRANSFORMED_IMAGE = TRANSFORMED["image"] # numpy.ndarray
TRANSFORMED_IMAGE_2 = LOADER_TRANSFORMED(image=IMAGE)["image"]
In this part, I want to save image after augmentation using
save_image as follows:
step 1: convert
TRAN_IMG_2 = torch.from_numpy(TRANSFORMED_IMAGE_2)
I got the error as follows:
RuntimeError: result type Float can’t be cast to the desired output type Byte
I’m not sure, Where did the error occur? because in save_image require tensor as input.