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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
RandomSunFlare dump #1072
Comments
Having a similar issue with OpenCV. Error Produced is:
Code is: import torchvision.transforms as T
import os
from PIL import Image
from torch.utils.data import Dataset
import numpy as np
from pycocotools.coco import COCO
import torch
import cv2
import albumentations as A
from albumentations.pytorch import ToTensorV2
class YoHouDataset(Dataset):
def __init__(self, image_dir, transform = None):
self.image_dir = image_dir
self.transform = transform
self.images = os.listdir(image_dir)
self.path_annotations = os.path.join(os.getcwd(),"Flug1_105Media_coco.json")
# self.f = open(self.path_annotations, 'r')
# self.db = json.load(self.f)
self.coco=COCO(self.path_annotations)
def __len__(self):
return len(self.images)
def __getitem__(self, index):
img_path = os.path.join(self.image_dir, self.images[index])
image_id = index
image_ = np.load(img_path,allow_pickle=True)[:,:,3]
cv2.imshow('test_image',image_)
cv2.waitKey(0) #wait for a keyboard input
cv2.destroyAllWindows()
# image_ = torch.as_tensor(image_)
image_height = image_.shape[0]
image_width = image_.shape[1]
#This will create the mask
mask_ = np.zeros((image_height, image_width))
category = 0
annIds = self.coco.getAnnIds(imgIds=image_id,catIds=category)
anns = self.coco.loadAnns(annIds)
for i in range(len(anns)):
mask_ += (self.coco.annToMask(anns[i])*(i+1))
mask_ += 1
mask_ -= np.unique(mask_)[0]
obj_ids = np.unique(mask_)
obj_ids = obj_ids[1:]
masks_ = mask_ == obj_ids[:, None, None]
print(type(masks_))
# masks = torch.as_tensor(masks, dtype=torch.uint8)
print(f"Loaded Picture {index}")
if self.transform is not None:
augmentations = self.transform(image=image_, mask=masks_)
image = augmentations['image']
masks = augmentations['mask']
# image, masks = self.transform(image, masks)
return image, masks
def get_transform(train):
transforms = []
transforms.append(T.ToTensor())
if train:
transforms.append(T.RandomHorizontalFlip(0.5))
return T.Compose(transforms)
if __name__ == "__main__":
IMAGE_HEIGHT = 2400 #Originally 2400
IMAGE_WIDTH = 3200 #Originally 3200
TRAIN_IMG_DIR = "images/Flug1_105Media/"
train_transforms = A.Compose(
[
# A.Resize(height=IMAGE_HEIGHT, width=IMAGE_WIDTH),
A.Rotate(limit=35, p=1.0),
A.HorizontalFlip(p=0.5),
A.VerticalFlip(p=0.1),
A.Normalize(
mean = [0.0, 0.0, 0.0],
std = [1.0, 1.0, 1.0],
max_pixel_value = 255.0,
),
ToTensorV2(),
],
)
train_ds = YoHouDataset(
image_dir=TRAIN_IMG_DIR,
transform=train_transforms,#transform=get_transform(train=True),
)
image, mask = next(iter(train_ds)) |
@Tim5Tang https://www.youtube.com/watch?v=NlhUpZKmzJ4&ab_channel=crazzylearners Although majority of the video is in Hindi, the basic gist of it is that if you input a wrong datatype into a function, it will result in the OpenCV giving an error. In the video he starts off by inputting an image, then he instead inputs a string and he gets the same error to spit out. He then inputs the image, but changes a different variable to produce a different error. The error we're seeing is an OpenCV error due to inputting the wrong type. |
@bilal-sher-nyu ok, thanks, i will test it, may be i have input the wrong type. |
the problem happens to me..how do u fix it? I am pretty sure that the input type is right |
Does the problem exist on the in latest version of the library? |
thanks, but it still doesnot work... |
Please, provide minimal reproducible example. |
@Dipet I have the same the same issue as the first post:
However I cannot make a reproducible example. During my trainings, the error appeared seemingly randomly after 40 and 28 epochs. I thought it might be a bad combination of augmentations, so I put all the probabilities at one in an attempt to reproduce it, but the error still does not appear straight away. Environment
|
So was I! The error occurs at random in the training stage. |
@Dipet I wrote a script to just keep making new images until it broke printing out the center, and can say with some certainty that the problem has to do with python ints not being 64 bit, but opencv being implemented in cpp using 64 bit ints. Full code here (repro for me took ~24 hours using this single threaded approach).
Patch to add debug prints
Output (clipped obviously)
|
The root cause is https://github.com/albumentations-team/albumentations/blob/master/albumentations/augmentations/transforms.py#L689
I'm not sure I understand the goal of the |
If I understand this correctly, basically when the angle is pi/2 or 3pi/2 the sun is directly above or below, so the sampling of centers along the x direction doesn't work. My trivial fix to clip will at least remove the crashes but will leave behind a "data" bug at samples near pi/2 and 3pi/2. I believe there might already be a bit of a data bug here because the range of tan is covered in pi, not 2pi, so I believe the current approach might be difficult to parameterize since it is double sampling the range. A more complete fix would be to generate points from the the line defined by centroid and the angle and then sample along that line both in the positive and negative direction. |
Also if anyone stumbles on this before the fix is put in, you can workaround this issue by limiting the range of the input to
|
馃悰 Bug
To Reproduce
add function
A.RandomSunFlare(p=0.2)
Steps to reproduce the behavior:
/Pytorch/lib/python3.6/site-packages/albumentations/augmentations/functional.py", line 863, in add_sun_flare
cv2.circle(overlay, (x, y), rad3, (r_color, g_color, b_color), -1)
cv2.error: OpenCV(4.5.4) 馃憥 error: (-5:Bad argument) in function 'circle'
Expected behavior
Environment
conda
,pip
, source): pipAdditional context
The text was updated successfully, but these errors were encountered: