def load_data(self, data: SampleCollection, dataset: Optional[Any] = None) -> Sequence[Mapping[str, Any]]: self._validate(data) label_path = data._get_label_field_path(self.label_field, "label")[1] filepaths = data.values("filepath") targets = data.values(label_path) classes = self._get_classes(data) if dataset is not None: dataset.num_classes = len(classes) class_to_idx = {cls_name: i for i, cls_name in enumerate(classes)} if targets and isinstance(targets[0], list): def to_idx(t): return [class_to_idx[x] for x in t] else: def to_idx(t): return class_to_idx[t] return [{ DefaultDataKeys.INPUT: f, DefaultDataKeys.TARGET: to_idx(t), } for f, t in zip(filepaths, targets)]
def load_data(self, data: SampleCollection, dataset: Optional[Any] = None) -> Sequence[Dict[str, Any]]: self._validate(data) data.compute_metadata() classes = self._get_classes(data) class_map = ClassMap(classes) dataset.num_classes = len(class_map) parser = FiftyOneParser(data, class_map, self.label_field, self.iscrowd) records = parser.parse(data_splitter=SingleSplitSplitter()) return [{DefaultDataKeys.INPUT: record} for record in records[0]]
def load_data( self, data: SampleCollection, dataset: Optional[Any] = None) -> Sequence[Mapping[str, Any]]: self._validate(data) self._fo_dataset_name = data.name return [{DefaultDataKeys.INPUT: f} for f in data.values("filepath")]
def _make_encoded_video_dataset(self, data: SampleCollection) -> 'EncodedVideoDataset': classes = self._get_classes(data) label_to_class_mapping = dict(enumerate(classes)) class_to_label_mapping = {c: lab for lab, c in label_to_class_mapping.items()} filepaths = data.values("filepath") labels = data.values(self.label_field + ".label") targets = [class_to_label_mapping[lab] for lab in labels] labeled_video_paths = LabeledVideoPaths(list(zip(filepaths, targets))) ds: EncodedVideoDataset = EncodedVideoDataset( labeled_video_paths, self.clip_sampler, video_sampler=self.video_sampler, decode_audio=self.decode_audio, decoder=self.decoder, ) return ds
def load_data(self, data: SampleCollection, dataset: Optional[Any] = None) -> Sequence[Dict[str, Any]]: self._validate(data) data.compute_metadata() filepaths = data.values("filepath") widths = data.values("metadata.width") heights = data.values("metadata.height") labels = data.values(self.label_field + ".detections.label") bboxes = data.values(self.label_field + ".detections.bounding_box") iscrowds = data.values(self.label_field + ".detections." + self.iscrowd) classes = self._get_classes(data) class_to_idx = {cls_name: i for i, cls_name in enumerate(classes)} if dataset is not None: dataset.num_classes = len(classes) output_data = [] img_id = 1 for fp, w, h, sample_labs, sample_boxes, sample_iscrowd in zip( filepaths, widths, heights, labels, bboxes, iscrowds): output_boxes = [] output_labs = [] output_iscrowd = [] output_areas = [] for lab, box, iscrowd in zip(sample_labs, sample_boxes, sample_iscrowd): output_box, output_area = self._reformat_bbox( box[0], box[1], box[2], box[3], w, h) output_areas.append(output_area) output_labs.append(class_to_idx[lab]) output_boxes.append(output_box) if iscrowd is None: iscrowd = 0 output_iscrowd.append(iscrowd) output_data.append( dict(input=fp, target=dict( boxes=output_boxes, labels=output_labs, image_id=img_id, area=output_areas, iscrowd=output_iscrowd, ))) img_id += 1 return output_data
def predict_load_data(self, data: SampleCollection, dataset: Optional[Any] = None) -> Sequence[Mapping[str, Any]]: return [{DefaultDataKeys.INPUT: f} for f in data.values("filepath")]