conradry / copy-paste-aug Goto Github PK
View Code? Open in Web Editor NEWCopy-paste augmentation for segmentation and detection tasks
License: MIT License
Copy-paste augmentation for segmentation and detection tasks
License: MIT License
Running the example jupyter , the "bboxes" is [] for both img_data and paste_img_data in code
img_data = self.copy_paste(**img_data, **paste_img_data)
. The empty bboxe causes the augmentation failed. I'm sure that "bboxes" extracted from annotations. My data is standard coco format. And the program works when drop other aug before CopyPaste.
img_data = self.load_example(idx) File "/home/sanjayghanagiri/copy-paste-aug/coco.py", line 54, in load_example img_id = self.ids[index] IndexError: list index out of range
I am facing issues with finding right dataset to test.
I tried with http://images.cocodataset.org/zips/test2017.zip test dataset and get index out of range issue.
Can you anyone please provide the right dataset to test?
I have successfully run your program. Now I want to know how to use the data, to train the model directly, or to save the data and train the model with the original data?
Hi, may I ask you how to use this method to augment the dataset of semantic segmentation?
Thank you.
/usr/local/lib/python3.6/dist-packages/albumentations/core/composition.py in <listcomp>(.0)
97 "__class_fullname__": self.get_class_fullname(),
98 "p": self.p,
---> 99 "transforms": [t._to_dict() for t in self.transforms], # skipcq: PYL-W0212
100 }
101
AttributeError: 'CopyPaste' object has no attribute '_to_dict'
Hi, Thanks for your work. Could you tell me how do I use copy-paste-aug in instance segmentation. Thanks a lot :)
Hey @conradry,Thank you for your work!
Could you tell me how can i use the copy-paste augmentation in YOLOX. The dataset for YOLOX should be in COCO format, and I already have my custom dataset, so I tried do some copy-paste-aug on my data, but it didn't work...any idea how can I use it in yoloX?
And if theres is a way to save augmented data (img and annotations.json) to different folder, I'd be glad to know.
@conradry Very interesting work done. Thanks. The 'example.ipynb' does not display augmented images as presented in figure 2 of the original paper. Can you advise on how to reproduce and visualize the augmentation effect as observed in the newly created images as presented in Fig 2 of the paper?
As a user design data augmentation pipline that could be used in torchvision.transform.Compose or Extend and use custom pipelines, for excample. Thanks!
Thank you for your work. But may more situations should be considered. With no changes to your example script , the aug failed for my aerial image. There is no data format problem in the process.
Have you been able to reproduce the results achieved in the paper with this unofficial implementation?
how to integrate with detectron2?
I developed my own dataset class. However, I keep getting a strange error.
This is my code
from copy_paste import copy_paste_class
from torch.utils.data import Dataset
import torchvision.transforms as transforms
@copy_paste_class
class DatasetClass(Dataset):
def __init__(self, df, transforms = None):
self.df = df
self.transforms = transforms
def __len__(self):
return len(self.df)
def load_example(self,index):
#locally
# img_path = self.df['imagePath'][index]
# on DGX
img_path = self.df['imagePath'][index]
img_label = self.df['class'][index]
img_PIL = Image.open(img_path)
print('done')
if img_PIL.mode != "RGB":
img_PIL = img_PIL.convert('RGB')
border = (int(self.df['xmin'][index]),\
int(self.df['ymin'][index]),\
int(self.df['xmax'][index]),\
int(self.df['ymax'][index])) # left, top, right, bottom
img_PIL = img_PIL.crop(border)
image = img_PIL
image = self.transforms(image)
return image, img_label_idx
import albumentations as A
from albumentations.pytorch.transforms import ToTensorV2
from copy_paste import CopyPaste
transforms = A.Compose([
A.RandomScale(scale_limit=(-0.9, 1), p=1), #LargeScaleJitter from scale of 0.1 to 2
A.PadIfNeeded(256, 256, border_mode=0), #constant 0 border
A.HorizontalFlip(p=0.5),
CopyPaste(blend=True, sigma=1, pct_objects_paste=0.5, p=1)
], bbox_params=A.BboxParams(format="coco")
)
Finally, this is the error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/tmp/ipykernel_16726/2411785438.py in <module>
----> 1 dataset[0]
~/Desktop/nas/vision/Orjuwan/LDR/Experiments/LogoDetection/YOLOv5/copy_paste.py in __getitem__(self, idx)
298 self._split_transforms()
299
--> 300 img_data = self.load_example(idx)
301 if self.copy_paste is not None:
302 paste_idx = random.randint(0, self.__len__() - 1)
/tmp/ipykernel_16726/579992425.py in load_example(self, index)
29 img_PIL = img_PIL.crop(border)
30 image = img_PIL
---> 31 image = self.transforms(image)
32
33 return image, img_label_idx
~/anaconda3/lib/python3.8/site-packages/albumentations/core/composition.py in __call__(self, force_apply, *args, **data)
191 def __call__(self, *args, force_apply=False, **data):
192 if args:
--> 193 raise KeyError("You have to pass data to augmentations as named arguments, for example: aug(image=image)")
194 if self.is_check_args:
195 self._check_args(**data)
KeyError: 'You have to pass data to augmentations as named arguments, for example: aug(image=image)'
ValueError: Expected x_max for bbox (0.65, 0.51, 1.12, 0.64, 3) to be in the range [0.0, 1.0], got 1.1234809015877545
Augmentation I use:
aug_list = [A.Resize(800,800),
CopyPaste(blend=True, sigma=1, pct_objects_paste=0.6, p=0.5) #pct_objects_paste is a guess
]
transform = A.Compose(
aug_list, bbox_params=A.BboxParams(format="coco")
)
Can anyone tell me where is the problem?
Hi @conradry , first of all thanks for your great work,
I want to use copy paste to copy annotation from original image to a background image without annotations. How can I do it ?
Hey @conradry,
I'm curios to know how can i use the copy-paste augmentation in YOLO. Im using albumentations to do some augmentation on my custom dataset and I have added the copy-paste aug as you said in the readme file but im not able to make it work! im getting an error that needs the mask params... which I dont have it! any idea how can I use it in yolov5 detection??
transform = A.Compose([
A.NoOp(p=0.4),
A.RandomScale(p=0.2)
CopyPaste(blend=True, sigma=1, pct_objects_paste=0.5, p=1)
], bbox_params=A.BboxParams(format="pascal_voc"))
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.