-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathInput.go
123 lines (102 loc) · 2.28 KB
/
Input.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package layer
import tf "github.com/galeone/tensorflow/tensorflow/go"
type LInput struct {
name string
dtype DataType
shape tf.Shape
trainable bool
batchSize float64
inputTensor interface{}
sparse bool
ragged bool
weights []*tf.Tensor
}
func Input() *LInput {
i := &LInput{
batchSize: -1,
dtype: Float32,
inputTensor: nil,
sparse: false,
ragged: false,
name: UniqueName("input"),
}
return i
}
func (i *LInput) SetName(name string) *LInput {
i.name = name
return i
}
func (i *LInput) SetTrainable(trainable bool) *LInput {
i.trainable = trainable
return i
}
func (i *LInput) SetInputShape(inputShape tf.Shape) *LInput {
i.shape = inputShape
return i
}
func (i *LInput) SetBatchSize(batchSize float64) *LInput {
i.batchSize = batchSize
return i
}
func (i *LInput) SetDtype(dtype DataType) *LInput {
i.dtype = dtype
return i
}
func (i *LInput) SetSparse(sparse bool) *LInput {
i.sparse = sparse
return i
}
func (i *LInput) SetRagged(ragged bool) *LInput {
i.ragged = ragged
return i
}
func (i *LInput) GetShape() tf.Shape {
return i.shape
}
func (i *LInput) GetDtype() DataType {
return i.dtype
}
func (i *LInput) SetInputs(inputs ...Layer) Layer {
return i
}
func (i *LInput) GetInputs() []Layer {
return []Layer{}
}
func (i *LInput) GetName() string {
return i.name
}
func (i *LInput) GetLayerWeights() []*tf.Tensor {
return i.weights
}
type jsonConfigInput struct {
ClassName string `json:"class_name"`
Name string `json:"name"`
Config map[string]interface{} `json:"config"`
InboundNodes []interface{} `json:"inbound_nodes"`
}
func (i *LInput) GetKerasLayerConfig() interface{} {
var shape []interface{}
dims, _ := i.shape.ToSlice()
for _, dim := range dims {
if dim == -1 {
shape = append(shape, nil)
} else {
shape = append(shape, dim)
}
}
return jsonConfigInput{
ClassName: "InputLayer",
Name: i.name,
Config: map[string]interface{}{
"name": i.name,
"batch_input_shape": shape,
"dtype": i.dtype.String(),
"sparse": i.sparse,
"ragged": i.ragged,
},
InboundNodes: []interface{}{},
}
}
func (i *LInput) GetCustomLayerDefinition() string {
return ``
}