-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathkit-file.go
84 lines (72 loc) · 2.18 KB
/
kit-file.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package artifact
import (
"encoding/json"
"io"
"os"
"sigs.k8s.io/yaml"
)
type (
KitFile struct {
ManifestVersion string `json:"manifestVersion"`
Package Package `json:"package,omitempty"`
Code []Code `json:"code,omitempty"`
DataSets []DataSet `json:"datasets,omitempty"`
Models []TrainedModel `json:"models,omitempty"`
}
Package struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Description string `json:"description,omitempty"`
License string `json:"license,omitempty"`
Authors []string `json:"authors,omitempty"`
}
Code struct {
Path string `json:"path,omitempty"`
License string `json:"license,omitempty"`
Description string `json:"description,omitempty"`
}
DataSet struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
Description string `json:"description,omitempty"`
License string `json:"license,omitempty"`
Preprocessing string `json:"preprocessing,omitempty"`
}
TrainedModel struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
Framework string `json:"framework,omitempty"`
Version string `json:"version,omitempty"`
Description string `json:"description,omitempty"`
License string `json:"license,omitempty"`
Training *Training `json:"training,omitempty"`
Validation *Validation `json:"validation,omitempty"`
}
Training struct {
DataSet string `json:"dataset,omitempty"`
Parameters map[string]interface{} `json:"parameters,omitempty"`
}
Validation struct {
DataSet string `json:"dataset,omitempty"`
Metrics map[string]interface{} `json:"metrics,omitempty"`
}
)
func (kf *KitFile) LoadModel(file *os.File) error {
// Read the file
data, err := io.ReadAll(file)
if err != nil {
return err
}
err = yaml.Unmarshal(data, kf)
if err != nil {
return err
}
return nil
}
func (kf *KitFile) MarshalToJSON() ([]byte, error) {
jsonData, err := json.Marshal(kf)
if err != nil {
return nil, err
}
return jsonData, nil
}