-
Notifications
You must be signed in to change notification settings - Fork 5
/
object_detection.go
40 lines (31 loc) · 953 Bytes
/
object_detection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package hfapigo
import (
"encoding/json"
)
const RecommendedObjectDetectionModel = "facebook/detr-resnet-50"
type ObjectDetectionResponse struct {
// The label for the class (model specific) of a detected object.
Label string `json:"label,omitempty"`
// A float that represents how likely it is that the detected object belongs to the given class.
Score float64 `json:"score,omitempty"`
// Bounding box of the detected object
Box ObjectBox
}
type ObjectBox struct {
XMin int `json:"xmin,omitempty"`
YMin int `json:"ymin,omitempty"`
XMax int `json:"xmax,omitempty"`
YMax int `json:"ymax,omitempty"`
}
func SendObjectDetectionRequest(model, imageFile string) ([]*ObjectDetectionResponse, error) {
respBody, err := MakeHFAPIRequestWithMedia(model, imageFile)
if err != nil {
return nil, err
}
resps := []*ObjectDetectionResponse{}
err = json.Unmarshal(respBody, &resps)
if err != nil {
return nil, err
}
return resps, nil
}