Skip to main content

COCO

Struct COCO 

Source
pub struct COCO {
    pub dataset: Dataset,
    /* private fields */
}
Expand description

The COCO dataset API for loading, querying, and indexing annotations.

Fields§

§dataset: Dataset

Implementations§

Source§

impl COCO

Source

pub fn new(annotation_file: &Path) -> Result<Self>

Load a COCO annotation JSON file and build indices.

Source

pub fn from_dataset(dataset: Dataset) -> Self

Build a COCO object from an already-loaded Dataset.

Source

pub fn get_ann_ids( &self, img_ids: &[u64], cat_ids: &[u64], area_rng: Option<[f64; 2]>, is_crowd: Option<bool>, ) -> Vec<u64>

Get annotation IDs matching the given filters.

All filter parameters are optional (pass empty slices / None to skip).

Source

pub fn get_cat_ids( &self, cat_nms: &[&str], sup_nms: &[&str], cat_ids: &[u64], ) -> Vec<u64>

Get category IDs matching the given filters.

Source

pub fn get_img_ids(&self, img_ids: &[u64], cat_ids: &[u64]) -> Vec<u64>

Get image IDs matching the given filters.

Source

pub fn load_anns(&self, ids: &[u64]) -> Vec<&Annotation>

Load annotations by IDs.

Source

pub fn load_cats(&self, ids: &[u64]) -> Vec<&Category>

Load categories by IDs.

Source

pub fn load_imgs(&self, ids: &[u64]) -> Vec<&Image>

Load images by IDs.

Source

pub fn get_ann(&self, id: u64) -> Option<&Annotation>

Get a single annotation by ID.

Source

pub fn get_img(&self, id: u64) -> Option<&Image>

Get a single image by ID.

Source

pub fn get_cat(&self, id: u64) -> Option<&Category>

Get a single category by ID.

Source

pub fn get_ann_ids_for_img_cat(&self, img_id: u64, cat_id: u64) -> &[u64]

Get annotation IDs for a specific (image, category) pair.

Single HashMap lookup — much faster than get_ann_ids with filtering.

Source

pub fn get_ann_ids_for_img(&self, img_id: u64) -> &[u64]

Get annotation IDs for a specific image.

Source

pub fn nonempty_img_cat_pairs(&self) -> impl Iterator<Item = (u64, u64)> + '_

Returns (img_id, cat_id) pairs that have at least one annotation.

Used by COCOeval to enumerate only non-empty pairs instead of the full Cartesian product, which is critical for large-scale datasets.

Source

pub fn nonempty_img_ids(&self) -> impl Iterator<Item = u64> + '_

Returns image IDs that have at least one annotation (any category).

Used by COCOeval when use_cats = false (all categories treated as one).

Source

pub fn load_res(&self, res_file: &Path) -> Result<COCO>

Load detection/result annotations into a new COCO object.

The result file can be a JSON array of annotation dicts, or a JSON object with an annotations field. The result COCO object shares the images and categories from self.

Source

pub fn load_res_anns(&self, anns: Vec<Annotation>) -> Result<COCO>

Load detection results from an already-parsed list of annotations.

This is the in-memory equivalent of load_res. It applies the same area, segmentation, and bbox fixups and returns a new COCO object sharing the images and categories from self.

Prefer this over load_res when results are already in memory — it avoids a round-trip through the filesystem. The Python binding uses this internally when load_res is called with a list of dicts or a numpy array.

Source

pub fn ann_to_rle(&self, ann: &Annotation) -> Option<Rle>

Convert an annotation’s segmentation to RLE.

Source

pub fn ann_to_mask(&self, ann: &Annotation) -> Option<Vec<u8>>

Convert an annotation to a binary mask.

Source

pub fn filter( &self, cat_ids: Option<&[u64]>, img_ids: Option<&[u64]>, area_rng: Option<[f64; 2]>, drop_empty_images: bool, ) -> Dataset

Filter the dataset, returning a new Dataset with matching images, annotations, and categories.

Annotations are kept when they match all provided criteria. If drop_empty_images is true, images with no matching annotations are removed; otherwise all images are kept (intersected with img_ids if provided).

Source

pub fn merge(datasets: &[&Dataset]) -> Result<Dataset>

Merge multiple datasets into one.

All datasets must share the same category taxonomy (same names + supercategories). Image and annotation IDs are remapped to ensure global uniqueness.

Source

pub fn split( &self, val_frac: f64, test_frac: Option<f64>, seed: u64, ) -> (Dataset, Dataset, Option<Dataset>)

Split the dataset into train/val (and optionally test) subsets.

Images are shuffled deterministically using seed, then partitioned. All splits share the full category list.

Source

pub fn sample(&self, n: Option<usize>, frac: Option<f64>, seed: u64) -> Dataset

Sample a random subset of images (with their annotations).

Provide either n (exact count) or frac (fraction of images). The sample is deterministic given the same seed.

Source

pub fn stats(&self) -> DatasetStats

Compute dataset health-check statistics.

Source

pub fn healthcheck(&self) -> HealthReport

Run a health check on this dataset.

Source

pub fn healthcheck_compatibility(&self, dt: &COCO) -> HealthReport

Run a health check including GT/DT compatibility.

Auto Trait Implementations§

§

impl Freeze for COCO

§

impl RefUnwindSafe for COCO

§

impl Send for COCO

§

impl Sync for COCO

§

impl Unpin for COCO

§

impl UnsafeUnpin for COCO

§

impl UnwindSafe for COCO

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V