forked from rai-project/caffe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unmarshal.go
47 lines (39 loc) · 1.1 KB
/
unmarshal.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
package caffe
import (
"io/ioutil"
"github.com/Unknwon/com"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
)
func unmarshal(target proto.Message, protoFileName string) error {
if !com.IsFile(protoFileName) {
return errors.Errorf("%s is not a file", protoFileName)
}
buf, err := ioutil.ReadFile(protoFileName)
if err != nil {
return errors.Wrapf(err, "failed to open %s", protoFileName)
}
return proto.Unmarshal(buf, target)
}
func unmarshalText(target proto.Message, protoFileName string) error {
if !com.IsFile(protoFileName) {
return errors.Errorf("%s is not a file", protoFileName)
}
buf, err := ioutil.ReadFile(protoFileName)
if err != nil {
return errors.Wrapf(err, "failed to open %s", protoFileName)
}
return proto.UnmarshalText(string(buf), target)
}
// ReadBlob ...
func ReadBlob(protoFileName string) (*BlobProto, error) {
blob := new(BlobProto)
err := unmarshal(blob, protoFileName)
return blob, err
}
// ReadBlob ...
func ReadNet(protoTextFileName string) (*NetParameter, error) {
net := new(NetParameter)
err := unmarshalText(net, protoTextFileName)
return net, err
}