-
Notifications
You must be signed in to change notification settings - Fork 4
/
Resizing.go
executable file
·127 lines (108 loc) · 2.76 KB
/
Resizing.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
124
125
126
127
package layer
import tf "github.com/galeone/tensorflow/tensorflow/go"
type LResizing struct {
cropToAspectRatio bool
dtype DataType
height float64
inputs []Layer
interpolation string
name string
shape tf.Shape
trainable bool
width float64
layerWeights []*tf.Tensor
}
func Resizing(height float64, width float64) *LResizing {
return &LResizing{
cropToAspectRatio: false,
dtype: Float32,
height: height,
interpolation: "bilinear",
name: UniqueName("resizing"),
trainable: true,
width: width,
}
}
func (l *LResizing) SetCropToAspectRatio(cropToAspectRatio bool) *LResizing {
l.cropToAspectRatio = cropToAspectRatio
return l
}
func (l *LResizing) SetDtype(dtype DataType) *LResizing {
l.dtype = dtype
return l
}
func (l *LResizing) SetInterpolation(interpolation string) *LResizing {
l.interpolation = interpolation
return l
}
func (l *LResizing) SetName(name string) *LResizing {
l.name = name
return l
}
func (l *LResizing) SetShape(shape tf.Shape) *LResizing {
l.shape = shape
return l
}
func (l *LResizing) SetTrainable(trainable bool) *LResizing {
l.trainable = trainable
return l
}
func (l *LResizing) SetLayerWeights(layerWeights []*tf.Tensor) *LResizing {
l.layerWeights = layerWeights
return l
}
func (l *LResizing) GetShape() tf.Shape {
return l.shape
}
func (l *LResizing) GetDtype() DataType {
return l.dtype
}
func (l *LResizing) SetInputs(inputs ...Layer) Layer {
l.inputs = inputs
return l
}
func (l *LResizing) GetInputs() []Layer {
return l.inputs
}
func (l *LResizing) GetName() string {
return l.name
}
func (l *LResizing) GetLayerWeights() []*tf.Tensor {
return l.layerWeights
}
type jsonConfigLResizing struct {
ClassName string `json:"class_name"`
Name string `json:"name"`
Config map[string]interface{} `json:"config"`
InboundNodes [][][]interface{} `json:"inbound_nodes"`
}
func (l *LResizing) GetKerasLayerConfig() interface{} {
inboundNodes := [][][]interface{}{
{},
}
for _, input := range l.inputs {
inboundNodes[0] = append(inboundNodes[0], []interface{}{
input.GetName(),
0,
0,
map[string]bool{},
})
}
return jsonConfigLResizing{
ClassName: "Resizing",
Name: l.name,
Config: map[string]interface{}{
"crop_to_aspect_ratio": l.cropToAspectRatio,
"dtype": l.dtype.String(),
"height": l.height,
"interpolation": l.interpolation,
"name": l.name,
"trainable": l.trainable,
"width": l.width,
},
InboundNodes: inboundNodes,
}
}
func (l *LResizing) GetCustomLayerDefinition() string {
return ``
}