pub struct CocoWriter { /* private fields */ }Expand description
COCO writer for generating JSON and ZIP files.
§Example
use edgefirst_client::coco::{CocoDataset, CocoWriter};
let writer = CocoWriter::new();
let dataset = CocoDataset::default();
writer.write_json(&dataset, "annotations.json")?;Implementations§
Source§impl CocoWriter
impl CocoWriter
Sourcepub fn with_options(options: CocoWriteOptions) -> Self
pub fn with_options(options: CocoWriteOptions) -> Self
Create a new COCO writer with custom options.
Sourcepub fn write_json<P: AsRef<Path>>(
&self,
dataset: &CocoDataset,
path: P,
) -> Result<(), Error>
pub fn write_json<P: AsRef<Path>>( &self, dataset: &CocoDataset, path: P, ) -> Result<(), Error>
Write COCO dataset to a JSON file.
§Arguments
dataset- The COCO dataset to writepath- Output file path
Sourcepub fn write_zip<P: AsRef<Path>>(
&self,
dataset: &CocoDataset,
images: impl Iterator<Item = (String, Vec<u8>)>,
path: P,
) -> Result<(), Error>
pub fn write_zip<P: AsRef<Path>>( &self, dataset: &CocoDataset, images: impl Iterator<Item = (String, Vec<u8>)>, path: P, ) -> Result<(), Error>
Write COCO dataset to a ZIP file with images.
Creates a ZIP archive with:
annotations/instances.json- The COCO annotations- Images at their original relative paths
§Arguments
dataset- The COCO dataset to writeimages- Iterator of(filename, image_data)pairspath- Output ZIP file path
Sourcepub fn write_zip_from_dir<P: AsRef<Path>>(
&self,
dataset: &CocoDataset,
images_dir: P,
path: P,
) -> Result<(), Error>
pub fn write_zip_from_dir<P: AsRef<Path>>( &self, dataset: &CocoDataset, images_dir: P, path: P, ) -> Result<(), Error>
Write COCO dataset to a ZIP file with images from a source directory.
§Arguments
dataset- The COCO dataset to writeimages_dir- Directory containing source imagespath- Output ZIP file path
Sourcepub fn write_split_by_group<P: AsRef<Path>>(
&self,
dataset: &CocoDataset,
group_assignments: &[String],
images_source: Option<&Path>,
output_dir: P,
) -> Result<HashMap<String, usize>, Error>
pub fn write_split_by_group<P: AsRef<Path>>( &self, dataset: &CocoDataset, group_assignments: &[String], images_source: Option<&Path>, output_dir: P, ) -> Result<HashMap<String, usize>, Error>
Split a dataset by group and write each group to its own directory.
Creates a directory structure like:
output_dir/
├── train/
│ ├── annotations/instances_train.json
│ └── images/
│ └── *.jpg
└── val/
├── annotations/instances_val.json
└── images/
└── *.jpg§Arguments
dataset- The COCO dataset to splitgroup_assignments- Parallel array of group names for each imageimages_source- Optional source directory containing images to copyoutput_dir- Output root directory
§Returns
HashMap of group name → number of images written
Sourcepub fn write_split_by_group_zip<P: AsRef<Path>>(
&self,
dataset: &CocoDataset,
group_assignments: &[String],
images_source: Option<&Path>,
output_dir: P,
) -> Result<HashMap<String, usize>, Error>
pub fn write_split_by_group_zip<P: AsRef<Path>>( &self, dataset: &CocoDataset, group_assignments: &[String], images_source: Option<&Path>, output_dir: P, ) -> Result<HashMap<String, usize>, Error>
Split a dataset by group and write each group to its own ZIP archive.
Creates ZIP archives like:
output_dir/train.zipcontaining train splitoutput_dir/val.zipcontaining val split
§Arguments
dataset- The COCO dataset to splitgroup_assignments- Parallel array of group names for each imageimages_source- Optional source directory containing images to includeoutput_dir- Output directory for ZIP files
§Returns
HashMap of group name → number of images written
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CocoWriter
impl RefUnwindSafe for CocoWriter
impl Send for CocoWriter
impl Sync for CocoWriter
impl Unpin for CocoWriter
impl UnwindSafe for CocoWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more