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
ToTransform before Normalize causes Tensor no attribute astype Error #644
Comments
This is the expected behavior. Normalize expects numpy arrays, and ToTensor returns torch.Tensor |
what should be done in order to do it? |
Can you apply |
Yes. But is that fine? |
Now I am having this error when I use ShiftScale Rotate Error
My DataLoader/Dataset
|
Can you give reproducible example? Looks like mask or image is empty image. |
not really an empty image. how do i give reproducible example? |
This error indicates that your image has 0 height or width.
We need sample code with image and mask on which you receive these errors. |
DataLoader
Creator of n_channel_binary_mask
Albumentations
|
Looks like all works fine import requests
import matplotlib.pyplot as plt
import albumentations as A
import cv2
import numpy as np
response = requests.get("https://raw.githubusercontent.com/albumentations-team/albumentations_examples/master/notebooks/images/parrot.jpg")
img = cv2.imdecode(np.frombuffer(response.content, dtype=np.uint8), cv2.IMREAD_COLOR)
mask = np.zeros(img.shape[:2], dtype=np.float32)
mask[200:1000, 200:700] = 1
transforms = A.Compose([
A.HorizontalFlip(p=1),
A.ShiftScaleRotate(
shift_limit=0, # no resizing
scale_limit=0.1,
rotate_limit=10, # rotate
p=1,
border_mode=cv2.BORDER_CONSTANT
),
A.RandomRotate90(p=1),
A.Cutout(p=1),
A.RandomBrightnessContrast(
brightness_limit=0.2, contrast_limit=0.2, p=1
),
A.GridDistortion(p=1),
A.HueSaturationValue(p=1),
A.RandomContrast(p=1),
A.MedianBlur(p=1),
A.Normalize(),
])
res = transforms(image=img, mask=mask)
plt.subplot(221)
plt.imshow(img)
plt.subplot(222)
plt.imshow(mask, cmap="gray")
plt.subplot(223)
plt.imshow(res["image"])
plt.subplot(224)
plt.imshow(res["mask"], cmap="gray")
plt.show() |
This is my albumentations transform. Before, this was Normalize --> ToTensor.
Changing the order (which I think is the right order) produces an error.
When loading using DataLoader, it generates an error
The text was updated successfully, but these errors were encountered: