coco

package module
v0.0.0-...-0195d4d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2022 License: BSD-2-Clause Imports: 6 Imported by: 0

README

coco

coco dataset api for go

Author

forked from dereklstinson/coco modify by gaoyuan1

testcase

cd GolangAPI
go test -v --count=1 .

How to use

export CGO_ENABLED=1

go get -u github.com/aidezone/cocoapi/GolangAPI

go mod tidy

// main.go

package main

import (
    coco "github.com/aidezone/cocoapi/GolangAPI"
)

func main() {
    
    dataset, err = ioutil.ReadFile("../anno/stuff_val2017.json")
    if err !=nil{
        fmt.Println("err:", err)
        return
    }

    cocoApi := NewCocoApi(dataset);
    cocoApi.LoadAnns(cocoApi.GetAnnIds(cocoApi.GetImgIds(nil), nil, nil, 3))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeSegmentToMask

func DecodeSegmentToMask(segmentation SegmentationHelper) (mask []byte)

func IoUBB

func IoUBB(dt, gt BB, iscrowd []byte) (out []float64)

IoUBB -Compute intersection over union between bounding boxes. void bbIou( BB dt, BB gt, siz m, siz n, byte *iscrowd, double *o );

func IoURLE

func IoURLE(dt, gt *RLE, iscrowd []byte) (out []float64)

IoURLE Compute intersection over union between masks. void rleIou( RLE *dt, RLE *gt, siz m, siz n, byte *iscrowd, double *o );

func NonMaxSupBB

func NonMaxSupBB(dt BB, thresh float64) (keep []bool)

NonMaxSupBB non-maximum suppression between bounding boxes void bbNms( BB dt, siz n, uint *keep, double thr );

Types

type Annotation

type Annotation struct {
	ImageID int `json:"image_id,omitempty"`

	// PanopticSegmentation does not have this property
	ID int `json:"id,omitempty"`

	// PanopticSegmentation and ImageCaption does not have this property
	CategoryID   int        `json:"category_id,omitempty"`
	Segmentation Segment    `json:"segmentation,omitempty"`
	Area         float32    `json:"area,omitempty"`
	Bbox         [4]float32 `json:"bbox,omitempty"`

	// PanopticSegmentation and StuffSegmentation and ImageCaption does not have this property
	Iscrowd byte `json:"iscrowd,omitempty"`

	// ImageCaption own property
	Caption string `json:"caption,omitempty"`

	// KeypointDetection own property
	Keypoints    []float32 `json:"keypoints,omitempty"`
	NumKeypoints int       `json:"num_keypoints,omitempty"`

	// PanopticSegmentation own property
	FileName     string          `json:"file_name,omitempty"`
	SegmentsInfo []PSSegmentInfo `json:"segments_info,omitempty"`
}

Annotation is the object detection annotation

type BB

type BB []float64

BB bounding box

func (BB) ToRLE

func (b BB) ToRLE(h, w, n uint32) *RLE

ToRLE Convert bounding boxes to encoded masks. void rleFrBbox( RLE *R, const BB bb, siz h, siz w, siz n );

type Categories

type Categories struct {
	ID            int    `json:"id,omitempty"`
	Name          string `json:"name,omitempty"`
	Supercategory string `json:"supercategory,omitempty"`

	// KeypointDetection own property
	Keypoints []string `json:"keypoints,omitempty"`
	Skeleton  []Edge   `json:"skeleton,omitempty"`

	// PanopticSegmentation own property
	Isthing byte      `json:"isthing,omitempty"`
	Color   [3]uint32 `json:"color,omitempty"`
}

Categories is the object detection categories.

type Char

type Char struct {
	Cc unsafe.Pointer
}

Char contains a pointer to a c char string

func (*Char) ToRLE

func (c *Char) ToRLE(h, w uint32) *RLE

ToRLE Convert from compressed string representation of encoded mask. void rleFrString( RLE *R, char *s, siz h, siz w );

type CocoApi

type CocoApi struct {
	// contains filtered or unexported fields
}

func NewCocoApi

func NewCocoApi(datasetMeta []byte) *CocoApi

func (*CocoApi) GetAnnIds

func (api *CocoApi) GetAnnIds(imgIds, catIds, areaRng []int, iscrowd byte) (ids []int)

func (*CocoApi) GetCatIds

func (api *CocoApi) GetCatIds(names, supCatNames []string) (ids []int)

func (*CocoApi) GetImgIds

func (api *CocoApi) GetImgIds(catIds []int) (ids []int)

func (*CocoApi) LoadAnns

func (api *CocoApi) LoadAnns(ids []int) (list []Annotation)

func (*CocoApi) LoadCats

func (api *CocoApi) LoadCats(ids []int) (list []Categories)

func (*CocoApi) LoadImgs

func (api *CocoApi) LoadImgs(ids []int) (list []Image)

func (*CocoApi) ShowAnns

func (api *CocoApi) ShowAnns(ids []int) ([]interface{}, error)

type CocoData

type CocoData struct {
	Info        Information  `json:"info,omitempty"`
	Images      []Image      `json:"images,omitempty"`
	Annotations []Annotation `json:"annotations,omitempty"`
	Licenses    []License    `json:"licenses,omitempty"`

	// ImageCaption does not have this property
	Categories []Categories `json:"categories,omitempty"`
}

type Edge

type Edge [2]uint32

Edge desribes a 2 point edge Probably [x,y] I haven't tested it yet

type Image

type Image struct {
	ID           int    `json:"id,omitempty"`
	Width        int    `json:"width,omitempty"`
	Height       int    `json:"height,omitempty"`
	FileName     string `json:"file_name,omitempty"`
	License      int    `json:"license,omitempty"`
	FlickrURL    string `json:"flickr_url,omitempty"`
	CocoURL      string `json:"coco_url,omitempty"`
	DateCaptured string `json:"date_captured,omitempty"`
}

Image is the image information and is shared between all the dataformats

type Information

type Information struct {
	Year        int    `json:"year,omitempty"`
	Version     string `json:"version,omitempty"`
	Description string `json:"description,omitempty"`
	Contributor string `json:"contributor,omitempty"`
	URL         string `json:"url,omitempty"`
	DateCreated string `json:"date_created,omitempty"`
}

Information is basic image and Coco information and is shared between all the data formats

type License

type License struct {
	ID   int    `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
	URL  string `json:"url,omitempty"`
}

License is the license information and is shared between all the formats

type PSSegmentInfo

type PSSegmentInfo struct {
	ID         int        `json:"id,omitempty"`
	CategoryID int        `json:"category_id,omitempty"`
	Area       int        `json:"area,omitempty"`
	Bbox       [4]float32 `json:"bbox,omitempty"`
	Iscrowd    byte       `json:"iscrowd,omitempty"`
}

PSSegmentInfo contains segment info for the annotation

type RLE

type RLE struct {
	// contains filtered or unexported fields
}

RLE contains a pointer to an array of C.RLE

func InitRLEs

func InitRLEs(size uint32) *RLE

InitRLEs creates an array of *RLE which holds a pointer to an array of C.RLEs

func RLEFromPoly

func RLEFromPoly(poly *float64, k, h, w uint32) *RLE

RLEFromPoly Convert polygon to encoded mask. void rleFrPoly( RLE *R, const double *xy, siz k, siz h, siz w );

func (*RLE) AreaRLE

func (r *RLE) AreaRLE() []uint32

AreaRLE - Compute area of encoded masks. void rleArea( const RLE *R, siz n, uint *a );

func (*RLE) Decode

func (r *RLE) Decode() (mask []byte)

Decode binary masks encoded via RLE void rleDecode( const RLE *R, byte *mask, siz n );

func (*RLE) MergeFrom

func (r *RLE) MergeFrom(m *RLE, intersect bool)

MergeFrom - Compute union or intersection of encoded masks. merges m into r

func (*RLE) NonMaxSup

func (r *RLE) NonMaxSup(thresh float64) (keep []bool)

NonMaxSup - Compute non-maximum suppression between bounding masks void rleNms( RLE *dt, siz n, uint *keep, double thr );

func (*RLE) ToBB

func (r *RLE) ToBB() (bb BB)

ToBB bounding boxes surrounding encoded masks. void rleToBbox( const RLE *R, BB bb, siz n );

func (*RLE) ToChar

func (r *RLE) ToChar() *Char

ToChar Get compressed string representation of encoded mask. char* rleToString( const RLE *R );

type Segment

type Segment struct {
	SegmentationHelper
}

Segment interface a placeholder for Segmentation data structures It can either be an RLE or a Polygon

func (*Segment) UnmarshalJSON

func (s *Segment) UnmarshalJSON(jBytes []byte) error

type SegmentationHelper

type SegmentationHelper interface {
	SegmentationType() string
}

SegmentationHelper is used for segmentation

type SegmentationPolygon

type SegmentationPolygon [][]float32

func (*SegmentationPolygon) SegmentationType

func (s *SegmentationPolygon) SegmentationType() string

type SegmentationRLE

type SegmentationRLE struct {
	Counts string    `json:"counts,omitempty"`
	Size   [2]uint32 `json:"size,omitempty"`
}

func EncodeMaskToSegment

func EncodeMaskToSegment(mask []byte, size [2]uint32) *SegmentationRLE

func EncodeRLEToSegment

func EncodeRLEToSegment(segmentation *SegmentationRLEUncompressed) *SegmentationRLE

func (*SegmentationRLE) SegmentationType

func (s *SegmentationRLE) SegmentationType() string

type SegmentationRLEUncompressed

type SegmentationRLEUncompressed struct {
	Counts []uint32  `json:"counts,omitempty"`
	Size   [2]uint32 `json:"size,omitempty"`
}

func (*SegmentationRLEUncompressed) SegmentationType

func (s *SegmentationRLEUncompressed) SegmentationType() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL