-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathattributes.go
58 lines (56 loc) · 1.64 KB
/
attributes.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
package onnx
import (
pb "github.com/owulveryck/onnx-go/internal/pb-onnx"
)
func toOperationAttributes(attrs []*pb.AttributeProto) (map[string]interface{}, error) {
output := make(map[string]interface{}, len(attrs))
for _, attr := range attrs {
switch attr.GetType() {
case pb.AttributeProto_UNDEFINED:
output[attr.Name] = struct{}{}
case pb.AttributeProto_FLOAT:
output[attr.Name] = attr.GetF()
case pb.AttributeProto_INT:
output[attr.Name] = attr.GetI()
case pb.AttributeProto_STRING:
output[attr.Name] = string(attr.GetS())
case pb.AttributeProto_TENSOR:
t, err := attr.GetT().Tensor()
if err != nil {
return nil, err
}
output[attr.Name] = t
case pb.AttributeProto_GRAPH:
return nil, &ErrNotImplemented{
AttributeName: attr.Name,
AttributeValue: attr,
Message: "pb.AttributeProto_GRAPH not handled yet",
}
case pb.AttributeProto_FLOATS:
output[attr.Name] = attr.GetFloats()
case pb.AttributeProto_INTS:
output[attr.Name] = attr.GetInts()
case pb.AttributeProto_STRINGS:
output[attr.Name] = attr.GetFloats()
case pb.AttributeProto_TENSORS:
return nil, &ErrNotImplemented{
AttributeName: attr.Name,
AttributeValue: attr,
Message: "pb.AttributeProto_TENSORS not handled yet",
}
case pb.AttributeProto_GRAPHS:
return nil, &ErrNotImplemented{
AttributeName: attr.Name,
AttributeValue: attr,
Message: "pb.AttributeProto_GRAPHS not handled yet",
}
default:
return nil, &ErrNotImplemented{
AttributeName: attr.Name,
AttributeValue: attr,
Message: "undefined attributeproto type",
}
}
}
return output, nil
}