-
Notifications
You must be signed in to change notification settings - Fork 1
/
accuracy.go
67 lines (54 loc) · 1.46 KB
/
accuracy.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package evaluation
import (
"fmt"
"time"
"gopkg.in/mgo.v2/bson"
"upper.io/db.v3"
"github.com/rai-project/database"
"github.com/rai-project/database/mongodb"
"github.com/rai-project/dlframework"
)
//easybson:json
type ModelAccuracy struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id,omitempty"`
CreatedAt time.Time `bson:"created_at,omitempty" json:"created_at,omitempty"`
Top1 float64 `bson:"top_1" json:"top_1"`
Top5 float64 `bson:"top_5" json:"top_5"`
}
func (ModelAccuracy) TableName() string {
return "model_accuracy"
}
type ModelAccuracyCollection struct {
*mongodb.MongoTable
}
func NewModelAccuracyCollection(db database.Database) (*ModelAccuracyCollection, error) {
tbl, err := mongodb.NewTable(db, ModelAccuracy{}.TableName())
if err != nil {
fmt.Print("here")
return nil, err
}
tbl.Create(nil)
return &ModelAccuracyCollection{
MongoTable: tbl.(*mongodb.MongoTable),
}, nil
}
func (c *ModelAccuracyCollection) Find(as ...interface{}) ([]ModelAccuracy, error) {
accs := []ModelAccuracy{}
collection := c.Session.Collection(c.Name())
err := collection.Find(as...).All(&accs)
if err != nil {
return nil, err
}
return accs, nil
}
func (c *ModelAccuracyCollection) FindByModel(model dlframework.ModelManifest) ([]ModelAccuracy, error) {
return c.Find(
db.Cond{
"model.name": model.Name,
"model.version": model.Version,
},
)
}
func (m *ModelAccuracyCollection) Close() error {
return nil
}