class TestTypeDataset: def __init__(self, opt, use_difficult=True, id_file=None, img_dir=None, anno_dir=None): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir, id_file=id_file, img_dir=img_dir, anno_dir=anno_dir, use_difficult=use_difficult) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img = preprocess(ori_img) return img, ori_img.shape[1:], bbox, label, difficult def __len__(self): return len(self.db)
class TestDataset: def __init__(self, opt, split='test', use_difficult=True): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir, split=split, use_difficult=use_difficult) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img = preprocess(ori_img) return img, ori_img.shape[1:], bbox, label, difficult def __len__(self): return len(self.db)
class TestDataset: def __init__(self, opt): self.opt = opt self.db = VOCBboxDataset(self.opt.test_data_dir) def __getitem__(self, idx): ori_img, bbox, label, difficult, mask = self.db.get_example(idx) img, mask = preprocess(ori_img, mask) return img, ori_img.shape[1:], bbox, label, difficult, mask def __len__(self): return len(self.db)
class TestDataset(object): def __init__(self): self.db = VOCBboxDataset( 'D:/pyworks/FasterRCNN/data/testset/VOCdevkit/VOC2007', 'test', True) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img = preprocess(ori_img) return img, ori_img.shape[1:], bbox, label, difficult def __len__(self): return len(self.db)
class TrainDataset(object): def __init__(self): self.db = VOCBboxDataset( 'D:/pyworks/FasterRCNN/data/VOCdevkit/VOC2007', 'trainval') self.transform = Transform() def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img, bbox, label, scale = self.transform((ori_img, bbox, label)) return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)
class Dataset: def __init__(self, opt): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir) self.tsf = Transform(opt.min_size, opt.max_size) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img, bbox, label, scale = self.tsf((ori_img, bbox, label)) return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)
class TestFGSMDataset: def __init__(self, opt, split='test', use_difficult=True): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir, split=split, use_difficult=use_difficult) self.tsf = Transform(opt.min_size, opt.max_size) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) _, _, _, scale = self.tsf((ori_img, bbox, label)) img = preprocess(ori_img) return img, ori_img.shape[1:], bbox, label, difficult, scale def __len__(self): return len(self.db)
class TestDataset: def __init__(self, configurations, split='val', use_difficult=True): self.configurations = configurations self.db = VOCBboxDataset(configurations.voc_data_dir, split=split, use_difficult=use_difficult) def __getitem__(self, idx): ori_image, bbox, label, difficult = self.db.get_example(idx) image = preprocess(ori_image) return image, ori_image.shape[1:], bbox, label, difficult def __len__(self): return len(self.db)
class Dataset: def __init__(self, opt): self.opt = opt self.dataset = VOCBboxDataset(opt.voc_data_dir) self.transform = Transform(opt.min_size, opt.max_size) def __getitem__(self, item): ori_img, bbox, label, difficult = self.dataset.get_example(item) img, bbox, label, scale = self.transform((ori_img, bbox, label)) return img.copy(), bbox.copy(), label.copy( ), scale #返回处理后的图片(CHW,[-1,1]),bbox,label,原图和调整后图的比例因子 def __len__(self): return len(self.dataset)
class Dataset: def __init__(self): self.db = VOCBboxDataset(voc_data_dir) self.tsf = Transform(min_size=600, max_size=1000) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img, bbox, label, scale = self.tsf((ori_img, bbox, label)) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)
class TestDataset: def __init__(self, opt, split='test', use_difficult=True): self.opt = opt self.db = VOCBboxDataset('/data2/dechunwang/dataset/', split=split, use_difficult=use_difficult) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) # print('\n', '*' * 70, 'ori_img shape: ', ori_img.shape, '\n', '*' * 70) img = preprocess(ori_img) # print('\n', '*' * 70, 'img shape: ', img.shape, '\n', '*' * 70) return ori_img, img, ori_img.shape[1:], bbox, label, difficult def __len__(self): return len(self.db)
class Dataset: def __init__(self, opt): self.opt = opt self.db = VOCBboxDataset(opt.train_data_dir) self.tsf = Transform() def __getitem__(self, idx): ori_img, bbox, label, difficult, mask = self.db.get_example(idx) img, bbox, label, scale, mask = self.tsf((ori_img, bbox, label, mask)) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale, mask.copy() def __len__(self): return len(self.db)
class SmallImageDataset: def __init__(self, opt): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir, split='trainval_small_32', small_obj=True) self.tsf = Transform(opt.min_size, opt.max_size) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img, bbox, label, scale = self.tsf((ori_img, bbox, label)) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)
class DatasetAugmented: def __init__(self, opt, id_file=None, img_dir=None, anno_dir=None, use_diff=True): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir, id_file=id_file, img_dir=img_dir, anno_dir=anno_dir, use_difficult=use_diff) self.tsf = Transform(opt.min_size, opt.max_size) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img, bbox, label, scale = self.tsf((ori_img, bbox, label)) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)
class Dataset: def __init__(self, opt): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir, opt.label_names) self.tsf = Transform(opt.min_size, opt.max_size) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img, bbox, label, scale = self.tsf((ori_img, bbox, label)) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), ori_img.shape[1:], bbox.copy(), \ label.copy(), scale, difficult def __len__(self): return len(self.db)
class TestDataset: # 测试集 有五个输出 def __init__(self, opt, split=opt.testtxt, use_difficult=True): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir, split=split, use_difficult=use_difficult) def __getitem__(self, idx): ori_img, bbox, label, difficult, id_ = self.db.get_example(idx) if len(bbox) == 0: return 0, ori_img.shape[1:], bbox, 0, 0, id_ img = preprocess(ori_img) return img, ori_img.shape[1:], bbox, label, difficult, id_ def __len__(self): return len(self.db)
class Dataset: def __init__(self, opt): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir) # 实例化类 self.tsf = Transform(opt.min_size, opt.max_size) # 获得变换类 def __getitem__(self, idx): # 运行Dataset自动运行 # 调用VOCBboxDataset中的get_example()将img, bbox, label, difficult一个个取出 ori_img, bbox, label, difficult = self.db.get_example(idx) # 调用前面的Transform函数将图片, label进行最小值最大值放缩归一化 img, bbox, label, scale = self.tsf((ori_img, bbox, label)) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)
class Dataset: def __init__(self, opt): self.opt = opt #预设参数 self.db = VOCBboxDataset(opt.voc_data_dir) #用预设参数创建数据集类 self.tsf = Transform(opt.min_size, opt.max_size) #实例化预处理类 def __getitem__(self, idx): #获得idx下标的一个数据 ori_img, bbox, label, difficult = self.db.get_example( idx) #从数据集中获得一个batch的数据 img, bbox, label, scale = self.tsf((ori_img, bbox, label)) #预处理数据 # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): #获得数据集总长度 return len(self.db)
class Dataset: def __init__(self, opt): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir) self.tsf = Transform(opt.min_size, opt.max_size) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example( idx ) #use voc_dataset.py VOCBboxDataset get_example() return img, bbox, label, difficult img, bbox, label, scale = self.tsf((ori_img, bbox, label)) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db) #trainval =5011 test=4952
class Dataset: #训练集样本的生成 def __init__(self, opt): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir) #实例化 类 self.tsf = Transform(opt.min_size, opt.max_size) def __getitem__(self, idx): #__ xxx__运行Dataset类时自动运行 ori_img, bbox, label, difficult = self.db.get_example(idx) #调用VOCBboxDataset中的get_example()从数据集存储路径中将img, bbox, label, difficult 一个个的获取出来 img, bbox, label, scale = self.tsf((ori_img, bbox, label)) #调用前面的Transform函数将图片,label进行最小值最大值放缩归一化,重新调整bboxes的大小,然后随机反转,最后将数据集返回 # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)
class TestDataset: def __init__(self, opt, split='test', use_difficult=True): self.opt = opt if self.opt.data == 'markers': self.db = MarkersDataset(opt.data_dir) elif self.opt.data == 'voc': self.db = VOCBboxDataset(opt.data_dir) else: raise Exception('database type not recognised: {}'.format( self.opt.data)) self.label_names = self.db.get_label_names() def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img = preprocess(ori_img) return img, ori_img.shape[1:], bbox, label, difficult def __len__(self): return len(self.db)
class TestDataset: def __init__(self, opt, split='test', use_difficult=True): self.opt = opt if opt.data == 'cityperson': self.db = CityPersonTestset( img_path=opt.cityperson_data_dir + '/leftImg8bit/val', annotation_path=opt.cityperson_data_dir + '/gtBboxCityPersons/val') else: self.db = VOCBboxDataset(opt.voc_data_dir, split=split, use_difficult=use_difficult) def __getitem__(self, idx): ori_img, bbox, label, difficult, image_id = self.db.get_example(idx) img = preprocess(ori_img) return img, ori_img.shape[1:], bbox, label, difficult, image_id def __len__(self): return len(self.db)
class Dataset: def __init__(self, opt): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir) self.tsf = Transform(opt.min_size, opt.max_size) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) # print("dataset getitem input: ", bbox, bbox.shape) # print("difficult", type(difficult), difficult, difficult.shape) img, bbox, label, scale = self.tsf((ori_img, bbox, label)) #print(bbox, label) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. #print("Dataset copied output:", bbox.copy(), bbox.copy().shape) return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)
class VOC2007Detect(Dataset): def __init__(self, path, is_train=True, min_size=600, max_size=1000): self.path = path self.is_train = is_train if self.is_train: self.db = VOCBboxDataset(path) self.tsf = Transform(min_size, max_size) else: self.db = VOCBboxDataset(path, split='val', use_difficult=True) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) if self.is_train: img, bbox, label, scale = self.tsf((ori_img, bbox, label)) return img, bbox, label, scale else: img = preprocess(ori_img) return img, ori_img.shape[1:], bbox, label, difficult def __len__(self): return len(self.db)
class Dataset: def __init__(self, opt): self.opt = opt if opt.data == 'cityperson': self.db = CityPersonTrainset( img_path=opt.cityperson_data_dir + '/leftImg8bit/train', annotation_path=opt.cityperson_data_dir + '/gtBboxCityPersons/train') else: self.db = VOCBboxDataset(opt.voc_data_dir) self.tsf = Transform(opt.min_size, opt.max_size) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img, bbox, label, scale = self.tsf((ori_img, bbox, label)) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)
class Dataset: # opt.voc_data_dir = '/home/featurize/data/VOCdevkit/VOC2007/' # min_size = 600 # image resize # max_size = 1000 # image resize # min_size 与 max_size 主要是因为我们图片要求 短边<=600 ,长边<= 1000 def __init__(self, opt): self.opt = opt self.db = VOCBboxDataset(opt.voc_data_dir) self.tsf = Transform(opt.min_size, opt.max_size) # —getitem__可以简单的理解为从数据集存储路径中将例子一个个的获取出来, # 然后调用前面的Transform函数将图片,label进行最小值最大值放缩归一化, # 重新调整bboxes的大小,然后随机反转,最后将数据集返回! def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img, bbox, label, scale = self.tsf((ori_img, bbox, label)) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)
class TrainDataset: """ 训练使用的数据集 __getitem__ : 返回图片,包围盒,标签以及归一化图片时的放缩倍数 img : shape = (channel, height/y-axis, width/x-axis) dtype = float32 归一化处理后的图片,归一方法根据pytorch还是caffe不一样 bbox : shape = (num_bbox, 4) => (y_{min}, x_{min}, y_{max}, x_{max}) dtype = float32 label : shape = (num_bbox, ) dtype = int32 scale : 使用Transform将图片放缩到指定范围,bbox也随之发生改变 """ def __init__(self, opt): self.opt = opt if opt.data == 'voc': self.db = VOCBboxDataset(opt.voc_data_dir) elif opt.data == 's3d': self.db = S3DBboxDataset(opt.s3d_data_dir) self.tsf = Transform(opt.min_size, opt.max_size) def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img, bbox, label, scale = self.tsf((ori_img, bbox, label)) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)
class Dataset: def __init__(self, opt): self.opt = opt if self.opt.data == 'markers': self.db = MarkersDataset(opt.data_dir) elif self.opt.data == 'voc': self.db = VOCBboxDataset(opt.data_dir) else: raise Exception('database type not recognised: {}'.format( self.opt.data)) self.tsf = Transform(opt.min_size, opt.max_size) self.label_names = self.db.get_label_names() def __getitem__(self, idx): ori_img, bbox, label, difficult = self.db.get_example(idx) img, bbox, label, scale = self.tsf((ori_img, bbox, label)) # TODO: check whose stride is negative to fix this instead copy all # some of the strides of a given numpy array are negative. return img.copy(), bbox.copy(), label.copy(), scale def __len__(self): return len(self.db)