-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.go
55 lines (48 loc) · 1.05 KB
/
util.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
package util
import (
"os"
"path/filepath"
"github.com/patrikeh/go-deep/training"
)
// IBrainUtil is interface of making assets for go-deep
type IBrainUtil interface {
Decode(string) ([]float64, error)
Encode([]float64) (interface{}, error)
MakePattern() ([]DataSet, error)
}
type DataSet training.Example
type DataSets training.Examples
func OpenOrCreateFile(path string) (*os.File, error) {
cDir, err := os.Getwd()
if err != nil {
return nil, err
}
file, err := os.OpenFile(filepath.Join(cDir, path), os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
return nil, err
}
return file, nil
}
func OpenDirFiles(path string) ([]string, error) {
cDir, err := os.Getwd()
if err != nil {
return nil, err
}
file, err := os.Open(filepath.Join(cDir, path))
if err != nil {
return nil, err
}
defer file.Close()
names, err := file.Readdirnames(-1)
if err != nil {
return nil, err
}
return names, nil
}
func DatsetToDataSets(p []DataSet) DataSets {
res := make(DataSets, len(p))
for i, v := range p {
res[i] = training.Example(v)
}
return res
}