def export_sample(self, image_or_path, classification, metadata=None): is_image_path = self._is_image_path(image_or_path) _label = _parse_classification(classification) if _label is None: _label = "_unlabeled" self._class_counts[_label] += 1 if is_image_path: image_path = image_or_path else: img = image_or_path image_path = self._default_filename_patt % ( self._class_counts[_label]) filename = os.path.basename(image_path) name, ext = os.path.splitext(filename) key = (_label, filename) self._filename_counts[key] += 1 count = self._filename_counts[key] if count > 1: filename = name + ("-%d" % count) + ext out_image_path = os.path.join(self.export_dir, _label, filename) if is_image_path: etau.copy_file(image_path, out_image_path) else: etai.write(img, out_image_path)
def export_sample(self, sample): out_filepath = self._filename_maker.get_output_path(sample.filepath) etau.copy_file(sample.filepath, out_filepath) d = sample.to_dict() d["filepath"] = os.path.relpath(out_filepath, self.export_dir) self._samples.append(d)
def download(self, storage_path, local_path): '''Downloads the file from storage. Args: storage_path: the path to the storage location local_path: the path to store the downloaded file locally ''' etau.copy_file(storage_path, local_path)
def upload(self, local_path, storage_path): '''Uploads the file to storage. Args: local_path: the path to the file to upload storage_path: the path to the storage location ''' etau.copy_file(local_path, storage_path)
def export_sample(self, sample): out_filepath = self._filename_maker.get_output_path(sample.filepath) etau.copy_file(sample.filepath, out_filepath) sd = sample.to_dict() sd["filepath"] = os.path.relpath(out_filepath, self.export_dir) if self._is_video_dataset: # Serialize frame labels separately uuid = os.path.splitext(os.path.basename(out_filepath))[0] outpath = self._export_frame_labels(sample, uuid) sd["frames"] = os.path.relpath(outpath, self.export_dir) self._samples.append(sd)
def setUpClass(cls): urllib.request.urlretrieve(cls.image_url, cls.test_one) etau.copy_file(cls.test_one, cls.test_two) cls.dataset.add_sample(cls.sample1) cls.dataset.add_sample(cls.sample2) cls.sample1["scalar"] = 1 cls.sample1["label"] = fo.Classification(label="test") cls.sample1.tags.append("tag") cls.sample1["floats"] = [ 0.5, float("nan"), float("inf"), float("-inf"), ] cls.sample1.save()
def _export_video(video_path, filename_maker): """Exports the video, using the given :class:`fiftyone.core.utils.UniqueFilenameMaker` to generate the output path for the video. Args: video_path: the path to a video on disk filename_maker: a :class:`fiftyone.core.utils.UniqueFilenameMaker` to use to generate the output video path Returns: the path to the exported video """ out_video_path = filename_maker.get_output_path(video_path) etau.copy_file(video_path, out_video_path) return out_video_path
def _export_image_or_path(image_or_path, filename_maker): """Exports the image, using the given :class:`fiftyone.core.utils.UniqueFilenameMaker` to generate the output path for the image. Args: image_or_path: an image or the path to the image on disk filename_maker: a :class:`fiftyone.core.utils.UniqueFilenameMaker` to use to generate the output image path Returns: the path to the exported image """ if ExportsImages._is_image_path(image_or_path): image_path = image_or_path out_image_path = filename_maker.get_output_path(image_path) etau.copy_file(image_path, out_image_path) else: img = image_or_path out_image_path = filename_maker.get_output_path() etai.write(img, out_image_path) return out_image_path
def _ingest_image_from_path(self, sample_parser): image_path = sample_parser.get_image_path() output_image_path = self._filename_maker.get_output_path(image_path) etau.copy_file(image_path, output_image_path) return output_image_path
def _ingest_video(self, sample_parser): video_path = sample_parser.get_video_path() output_video_path = self._filename_maker.get_output_path(video_path) etau.copy_file(video_path, output_video_path) return output_video_path