forked from tensorflow/tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrappers.go
20372 lines (19327 loc) · 648 KB
/
wrappers.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2017 The TensorFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// DO NOT EDIT
// This file was machine generated by github.com/tensorflow/tensorflow/tensorflow/go/genop/internal
//
// WARNING: This generation of wrapper function for TensorFlow ops is in an
// experimental state. The generated API can change without notice.
package op
import tf "github.com/tensorflow/tensorflow/tensorflow/go"
// optionalAttr is an intentionally un-exported type to hide
// details of how optional attributes to operations are implemented.
type optionalAttr map[string]interface{}
func makeOutputList(op *tf.Operation, start int, output string) ([]tf.Output, int, error) {
size, err := op.OutputListSize(output)
if err != nil {
return nil, start, err
}
list := make([]tf.Output, size)
for i := 0; i < size; i++ {
list[i] = op.Output(start + i)
}
return list, start + size, nil
}
// Adds sparse updates to the variable referenced by `resource`.
//
// This operation computes
//
// # Scalar indices
// ref[indices, ...] += updates[...]
//
// # Vector indices (for each i)
// ref[indices[i], ...] += updates[i, ...]
//
// # High rank indices (for each i, ..., j)
// ref[indices[i, ..., j], ...] += updates[i, ..., j, ...]
//
// Duplicate entries are handled correctly: if multiple `indices` reference
// the same location, their contributions add.
//
// Requires `updates.shape = indices.shape + ref.shape[1:]`.
//
// <div style="width:70%; margin:auto; margin-bottom:10px; margin-top:20px;">
// <img style="width:100%" src="../../images/ScatterAdd.png" alt>
// </div>
//
// Arguments:
// resource: Should be from a `Variable` node.
// indices: A tensor of indices into the first dimension of `ref`.
// updates: A tensor of updated values to add to `ref`.
//
// Returns the created operation.
func ResourceScatterAdd(scope *Scope, resource tf.Output, indices tf.Output, updates tf.Output) (o *tf.Operation) {
if scope.Err() != nil {
return
}
opspec := tf.OpSpec{
Type: "ResourceScatterAdd",
Input: []tf.Input{
resource, indices, updates,
},
}
return scope.AddOperation(opspec)
}
// Checks whether a resource handle-based variable has been initialized.
//
// Arguments:
// resource: the input resource handle.
//
// Returns a scalar boolean which is true if the variable has been
// initialized.
func VarIsInitializedOp(scope *Scope, resource tf.Output) (is_initialized tf.Output) {
if scope.Err() != nil {
return
}
opspec := tf.OpSpec{
Type: "VarIsInitializedOp",
Input: []tf.Input{
resource,
},
}
op := scope.AddOperation(opspec)
return op.Output(0)
}
// Subtracts a value from the current value of a variable.
//
// Any ReadVariableOp which depends directly or indirectly on this assign is
// guaranteed to see the incremented value or a subsequent newer one.
//
// Outputs the incremented value, which can be used to totally order the
// increments to this variable.
//
// Arguments:
// resource: handle to the resource in which to store the variable.
// value: the value by which the variable will be incremented.
//
// Returns the created operation.
func AssignSubVariableOp(scope *Scope, resource tf.Output, value tf.Output) (o *tf.Operation) {
if scope.Err() != nil {
return
}
opspec := tf.OpSpec{
Type: "AssignSubVariableOp",
Input: []tf.Input{
resource, value,
},
}
return scope.AddOperation(opspec)
}
// Assigns a new value to a variable.
//
// Any ReadVariableOp with a control dependency on this op is guaranteed to return
// this value or a subsequent newer value of the variable.
//
// Arguments:
// resource: handle to the resource in which to store the variable.
// value: the value to set the new tensor to use.
//
// Returns the created operation.
func AssignVariableOp(scope *Scope, resource tf.Output, value tf.Output) (o *tf.Operation) {
if scope.Err() != nil {
return
}
opspec := tf.OpSpec{
Type: "AssignVariableOp",
Input: []tf.Input{
resource, value,
},
}
return scope.AddOperation(opspec)
}
// VarHandleOpAttr is an optional argument to VarHandleOp.
type VarHandleOpAttr func(optionalAttr)
// VarHandleOpContainer sets the optional container attribute to value.
//
// value: the container this variable is placed in.
// If not specified, defaults to ""
func VarHandleOpContainer(value string) VarHandleOpAttr {
return func(m optionalAttr) {
m["container"] = value
}
}
// VarHandleOpSharedName sets the optional shared_name attribute to value.
//
// value: the name by which this variable is referred to.
// If not specified, defaults to ""
func VarHandleOpSharedName(value string) VarHandleOpAttr {
return func(m optionalAttr) {
m["shared_name"] = value
}
}
// Creates a handle to a Variable resource.
//
// Arguments:
// dtype: the type of this variable. Must agree with the dtypes
// of all ops using this variable.
// shape: The (possibly partially specified) shape of this variable.
func VarHandleOp(scope *Scope, dtype tf.DataType, shape tf.Shape, optional ...VarHandleOpAttr) (resource tf.Output) {
if scope.Err() != nil {
return
}
attrs := map[string]interface{}{"dtype": dtype, "shape": shape}
for _, a := range optional {
a(attrs)
}
opspec := tf.OpSpec{
Type: "VarHandleOp",
Attrs: attrs,
}
op := scope.AddOperation(opspec)
return op.Output(0)
}
// Compute gradients for a FakeQuantWithMinMaxVarsPerChannel operation.
//
// Arguments:
// gradients: Backpropagated gradients above the FakeQuantWithMinMaxVars operation,
// shape one of: `[d]`, `[b, d]`, `[b, h, w, d]`.
// inputs: Values passed as inputs to the FakeQuantWithMinMaxVars operation, shape
// same as `gradients`.
// min, max: Quantization interval, floats of shape `[d]`.
//
//
//
// Returns Backpropagated gradients w.r.t. inputs, shape same as
// `inputs`:
// `gradients * (inputs >= min && inputs <= max)`.Backpropagated gradients w.r.t. min parameter, shape `[d]`:
// `sum_per_d(gradients * (inputs < min))`.Backpropagated gradients w.r.t. max parameter, shape `[d]`:
// `sum_per_d(gradients * (inputs > max))`.
func FakeQuantWithMinMaxVarsPerChannelGradient(scope *Scope, gradients tf.Output, inputs tf.Output, min tf.Output, max tf.Output) (backprops_wrt_input tf.Output, backprop_wrt_min tf.Output, backprop_wrt_max tf.Output) {
if scope.Err() != nil {
return
}
opspec := tf.OpSpec{
Type: "FakeQuantWithMinMaxVarsPerChannelGradient",
Input: []tf.Input{
gradients, inputs, min, max,
},
}
op := scope.AddOperation(opspec)
return op.Output(0), op.Output(1), op.Output(2)
}
// Fake-quantize the 'inputs' tensor of type float via global float scalars `min`
//
// and `max` to 'outputs' tensor of same shape as `inputs`.
//
// [min; max] is the clamping range for the 'inputs' data. Op divides this range
// into 255 steps (total of 256 values), then replaces each 'inputs' value with the
// closest of the quantized step values.
//
// This operation has a gradient and thus allows for training `min` and `max` values.
func FakeQuantWithMinMaxVars(scope *Scope, inputs tf.Output, min tf.Output, max tf.Output) (outputs tf.Output) {
if scope.Err() != nil {
return
}
opspec := tf.OpSpec{
Type: "FakeQuantWithMinMaxVars",
Input: []tf.Input{
inputs, min, max,
},
}
op := scope.AddOperation(opspec)
return op.Output(0)
}
// QuantizedInstanceNormAttr is an optional argument to QuantizedInstanceNorm.
type QuantizedInstanceNormAttr func(optionalAttr)
// QuantizedInstanceNormOutputRangeGiven sets the optional output_range_given attribute to value.
//
// value: If True, `given_y_min` and `given_y_min`
// and `given_y_max` are used as the output range. Otherwise,
// the implementation computes the output range.
// If not specified, defaults to false
func QuantizedInstanceNormOutputRangeGiven(value bool) QuantizedInstanceNormAttr {
return func(m optionalAttr) {
m["output_range_given"] = value
}
}
// QuantizedInstanceNormGivenYMin sets the optional given_y_min attribute to value.
//
// value: Output in `y_min` if `output_range_given` is True.
// If not specified, defaults to 0
func QuantizedInstanceNormGivenYMin(value float32) QuantizedInstanceNormAttr {
return func(m optionalAttr) {
m["given_y_min"] = value
}
}
// QuantizedInstanceNormGivenYMax sets the optional given_y_max attribute to value.
//
// value: Output in `y_max` if `output_range_given` is True.
// If not specified, defaults to 0
func QuantizedInstanceNormGivenYMax(value float32) QuantizedInstanceNormAttr {
return func(m optionalAttr) {
m["given_y_max"] = value
}
}
// QuantizedInstanceNormVarianceEpsilon sets the optional variance_epsilon attribute to value.
//
// value: A small float number to avoid dividing by 0.
// If not specified, defaults to 1e-05
func QuantizedInstanceNormVarianceEpsilon(value float32) QuantizedInstanceNormAttr {
return func(m optionalAttr) {
m["variance_epsilon"] = value
}
}
// QuantizedInstanceNormMinSeparation sets the optional min_separation attribute to value.
//
// value: Minimum value of `y_max - y_min`
// If not specified, defaults to 0.001
func QuantizedInstanceNormMinSeparation(value float32) QuantizedInstanceNormAttr {
return func(m optionalAttr) {
m["min_separation"] = value
}
}
// Quantized Instance normalization.
//
// Arguments:
// x: A 4D input Tensor.
// x_min: The value represented by the lowest quantized input.
// x_max: The value represented by the highest quantized input.
//
// Returns A 4D Tensor.The value represented by the lowest quantized output.The value represented by the highest quantized output.
func QuantizedInstanceNorm(scope *Scope, x tf.Output, x_min tf.Output, x_max tf.Output, optional ...QuantizedInstanceNormAttr) (y tf.Output, y_min tf.Output, y_max tf.Output) {
if scope.Err() != nil {
return
}
attrs := map[string]interface{}{}
for _, a := range optional {
a(attrs)
}
opspec := tf.OpSpec{
Type: "QuantizedInstanceNorm",
Input: []tf.Input{
x, x_min, x_max,
},
Attrs: attrs,
}
op := scope.AddOperation(opspec)
return op.Output(0), op.Output(1), op.Output(2)
}
// Concatenates quantized tensors along one dimension.
//
// Arguments:
// concat_dim: 0-D. The dimension along which to concatenate. Must be in the
// range [0, rank(values)).
// values: The `N` Tensors to concatenate. Their ranks and types must match,
// and their sizes must match in all dimensions except `concat_dim`.
// input_mins: The minimum scalar values for each of the input tensors.
// input_maxes: The maximum scalar values for each of the input tensors.
//
// Returns A `Tensor` with the concatenation of values stacked along the
// `concat_dim` dimension. This tensor's shape matches that of `values` except
// in `concat_dim` where it has the sum of the sizes.The float value that the minimum quantized output value represents.The float value that the maximum quantized output value represents.
func QuantizedConcat(scope *Scope, concat_dim tf.Output, values []tf.Output, input_mins []tf.Output, input_maxes []tf.Output) (output tf.Output, output_min tf.Output, output_max tf.Output) {
if scope.Err() != nil {
return
}
opspec := tf.OpSpec{
Type: "QuantizedConcat",
Input: []tf.Input{
concat_dim, tf.OutputList(values), tf.OutputList(input_mins), tf.OutputList(input_maxes),
},
}
op := scope.AddOperation(opspec)
return op.Output(0), op.Output(1), op.Output(2)
}
// QuantizeAndDequantizeAttr is an optional argument to QuantizeAndDequantize.
type QuantizeAndDequantizeAttr func(optionalAttr)
// QuantizeAndDequantizeSignedInput sets the optional signed_input attribute to value.
// If not specified, defaults to true
func QuantizeAndDequantizeSignedInput(value bool) QuantizeAndDequantizeAttr {
return func(m optionalAttr) {
m["signed_input"] = value
}
}
// QuantizeAndDequantizeNumBits sets the optional num_bits attribute to value.
// If not specified, defaults to 8
func QuantizeAndDequantizeNumBits(value int64) QuantizeAndDequantizeAttr {
return func(m optionalAttr) {
m["num_bits"] = value
}
}
// QuantizeAndDequantizeRangeGiven sets the optional range_given attribute to value.
// If not specified, defaults to false
func QuantizeAndDequantizeRangeGiven(value bool) QuantizeAndDequantizeAttr {
return func(m optionalAttr) {
m["range_given"] = value
}
}
// QuantizeAndDequantizeInputMin sets the optional input_min attribute to value.
// If not specified, defaults to 0
func QuantizeAndDequantizeInputMin(value float32) QuantizeAndDequantizeAttr {
return func(m optionalAttr) {
m["input_min"] = value
}
}
// QuantizeAndDequantizeInputMax sets the optional input_max attribute to value.
// If not specified, defaults to 0
func QuantizeAndDequantizeInputMax(value float32) QuantizeAndDequantizeAttr {
return func(m optionalAttr) {
m["input_max"] = value
}
}
// Use QuantizeAndDequantizeV2 instead.
//
// DEPRECATED at GraphDef version 22: Replaced by QuantizeAndDequantizeV2
func QuantizeAndDequantize(scope *Scope, input tf.Output, optional ...QuantizeAndDequantizeAttr) (output tf.Output) {
if scope.Err() != nil {
return
}
attrs := map[string]interface{}{}
for _, a := range optional {
a(attrs)
}
opspec := tf.OpSpec{
Type: "QuantizeAndDequantize",
Input: []tf.Input{
input,
},
Attrs: attrs,
}
op := scope.AddOperation(opspec)
return op.Output(0)
}
// OneHotAttr is an optional argument to OneHot.
type OneHotAttr func(optionalAttr)
// OneHotAxis sets the optional axis attribute to value.
//
// value: The axis to fill (default: -1, a new inner-most axis).
// If not specified, defaults to -1
func OneHotAxis(value int64) OneHotAttr {
return func(m optionalAttr) {
m["axis"] = value
}
}
// Returns a one-hot tensor.
//
// The locations represented by indices in `indices` take value `on_value`,
// while all other locations take value `off_value`.
//
// If the input `indices` is rank `N`, the output will have rank `N+1`,
// The new axis is created at dimension `axis` (default: the new axis is
// appended at the end).
//
// If `indices` is a scalar the output shape will be a vector of length `depth`.
//
// If `indices` is a vector of length `features`, the output shape will be:
// ```
// features x depth if axis == -1
// depth x features if axis == 0
// ```
//
// If `indices` is a matrix (batch) with shape `[batch, features]`,
// the output shape will be:
// ```
// batch x features x depth if axis == -1
// batch x depth x features if axis == 1
// depth x batch x features if axis == 0
// ```
//
//
// Examples
// =========
//
// Suppose that
//
// ```
// indices = [0, 2, -1, 1]
// depth = 3
// on_value = 5.0
// off_value = 0.0
// axis = -1
// ```
//
// Then output is `[4 x 3]`:
//
// ```output =
// [5.0 0.0 0.0] // one_hot(0)
// [0.0 0.0 5.0] // one_hot(2)
// [0.0 0.0 0.0] // one_hot(-1)
// [0.0 5.0 0.0] // one_hot(1)
// ```
//
// Suppose that
//
// ```
// indices = [0, 2, -1, 1]
// depth = 3
// on_value = 0.0
// off_value = 3.0
// axis = 0
// ```
//
// Then output is `[3 x 4]`:
//
// ```output =
// [0.0 3.0 3.0 3.0]
// [3.0 3.0 3.0 0.0]
// [3.0 3.0 3.0 3.0]
// [3.0 0.0 3.0 3.0]
// // ^ one_hot(0)
// // ^ one_hot(2)
// // ^ one_hot(-1)
// // ^ one_hot(1)
// ```
// Suppose that
//
// ```
// indices = [[0, 2], [1, -1]]
// depth = 3
// on_value = 1.0
// off_value = 0.0
// axis = -1
// ```
//
// Then output is `[2 x 2 x 3]`:
//
// ```output =
// [
// [1.0, 0.0, 0.0] // one_hot(0)
// [0.0, 0.0, 1.0] // one_hot(2)
// ][
// [0.0, 1.0, 0.0] // one_hot(1)
// [0.0, 0.0, 0.0] // one_hot(-1)
// ]```
//
// Arguments:
// indices: A tensor of indices.
// depth: A scalar defining the depth of the one hot dimension.
// on_value: A scalar defining the value to fill in output when `indices[j] = i`.
// off_value: A scalar defining the value to fill in output when `indices[j] != i`.
//
// Returns The one-hot tensor.
func OneHot(scope *Scope, indices tf.Output, depth tf.Output, on_value tf.Output, off_value tf.Output, optional ...OneHotAttr) (output tf.Output) {
if scope.Err() != nil {
return
}
attrs := map[string]interface{}{}
for _, a := range optional {
a(attrs)
}
opspec := tf.OpSpec{
Type: "OneHot",
Input: []tf.Input{
indices, depth, on_value, off_value,
},
Attrs: attrs,
}
op := scope.AddOperation(opspec)
return op.Output(0)
}
// Bitcasts a tensor from one type to another without copying data.
//
// Given a tensor `input`, this operation returns a tensor that has the same buffer
// data as `input` with datatype `type`.
//
// If the input datatype `T` is larger than the output datatype `type` then the
// shape changes from [...] to [..., sizeof(`T`)/sizeof(`type`)].
//
// If `T` is smaller than `type`, the operator requires that the rightmost
// dimension be equal to sizeof(`type`)/sizeof(`T`). The shape then goes from
// [..., sizeof(`type`)/sizeof(`T`)] to [...].
//
// *NOTE*: Bitcast is implemented as a low-level cast, so machines with different
// endian orderings will give different results.
func Bitcast(scope *Scope, input tf.Output, type_ tf.DataType) (output tf.Output) {
if scope.Err() != nil {
return
}
attrs := map[string]interface{}{"type": type_}
opspec := tf.OpSpec{
Type: "Bitcast",
Input: []tf.Input{
input,
},
Attrs: attrs,
}
op := scope.AddOperation(opspec)
return op.Output(0)
}
// Extract `patches` from `images` and put them in the "depth" output dimension.
//
// Arguments:
// images: 4-D Tensor with shape `[batch, in_rows, in_cols, depth]`.
// ksizes: The size of the sliding window for each dimension of `images`.
// strides: 1-D of length 4. How far the centers of two consecutive patches are in
// the images. Must be: `[1, stride_rows, stride_cols, 1]`.
// rates: 1-D of length 4. Must be: `[1, rate_rows, rate_cols, 1]`. This is the
// input stride, specifying how far two consecutive patch samples are in the
// input. Equivalent to extracting patches with
// `patch_sizes_eff = patch_sizes + (patch_sizes - 1) * (rates - 1)`, followed by
// subsampling them spatially by a factor of `rates`.
// padding: The type of padding algorithm to use.
//
// We specify the size-related attributes as:
//
// ```python
// ksizes = [1, ksize_rows, ksize_cols, 1]
// strides = [1, strides_rows, strides_cols, 1]
// rates = [1, rates_rows, rates_cols, 1]
// ```
//
// Returns 4-D Tensor with shape `[batch, out_rows, out_cols, ksize_rows *
// ksize_cols * depth]` containing image patches with size
// `ksize_rows x ksize_cols x depth` vectorized in the "depth" dimension.
func ExtractImagePatches(scope *Scope, images tf.Output, ksizes []int64, strides []int64, rates []int64, padding string) (patches tf.Output) {
if scope.Err() != nil {
return
}
attrs := map[string]interface{}{"ksizes": ksizes, "strides": strides, "rates": rates, "padding": padding}
opspec := tf.OpSpec{
Type: "ExtractImagePatches",
Input: []tf.Input{
images,
},
Attrs: attrs,
}
op := scope.AddOperation(opspec)
return op.Output(0)
}
// DepthToSpace for tensors of type T.
//
// Rearranges data from depth into blocks of spatial data.
// This is the reverse transformation of SpaceToDepth. More specifically,
// this op outputs a copy of the input tensor where values from the `depth`
// dimension are moved in spatial blocks to the `height` and `width` dimensions.
// The attr `block_size` indicates the input block size and how the data is moved.
//
// * Chunks of data of size `block_size * block_size` from depth are rearranged
// into non-overlapping blocks of size `block_size x block_size`
// * The width the output tensor is `input_depth * block_size`, whereas the
// height is `input_height * block_size`.
// * The depth of the input tensor must be divisible by
// `block_size * block_size`.
//
// That is, assuming the input is in the shape:
// `[batch, height, width, depth]`,
// the shape of the output will be:
// `[batch, height*block_size, width*block_size, depth/(block_size*block_size)]`
//
// This operation requires that the input tensor be of rank 4, and that
// `block_size` be >=1 and that `block_size * block_size` be a divisor of the
// input depth.
//
// This operation is useful for resizing the activations between convolutions
// (but keeping all data), e.g. instead of pooling. It is also useful for training
// purely convolutional models.
//
// For example, given this input of shape `[1, 1, 1, 4]`, and a block size of 2:
//
// ```prettyprint
// x = [[[[1, 2, 3, 4]]]]
//
// ```
//
// This operation will output a tensor of shape `[1, 2, 2, 1]`:
//
// ```prettyprint
// [[[[1], [2]],
// [[3], [4]]]]
// ```
//
// Here, the input has a batch of 1 and each batch element has shape `[1, 1, 4]`,
// the corresponding output will have 2x2 elements and will have a depth of
// 1 channel (1 = `4 / (block_size * block_size)`).
// The output element shape is `[2, 2, 1]`.
//
// For an input tensor with larger depth, here of shape `[1, 1, 1, 12]`, e.g.
//
// ```prettyprint
// x = [[[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]]]
// ```
//
// This operation, for block size of 2, will return the following tensor of shape
// `[1, 2, 2, 3]`
//
// ```prettyprint
// [[[[1, 2, 3], [4, 5, 6]],
// [[7, 8, 9], [10, 11, 12]]]]
//
// ```
//
// Similarly, for the following input of shape `[1 2 2 4]`, and a block size of 2:
//
// ```prettyprint
// x = [[[[1, 2, 3, 4],
// [5, 6, 7, 8]],
// [[9, 10, 11, 12],
// [13, 14, 15, 16]]]]
// ```
//
// the operator will return the following tensor of shape `[1 4 4 1]`:
//
// ```prettyprint
// x = [[ [1], [2], [5], [6]],
// [ [3], [4], [7], [8]],
// [ [9], [10], [13], [14]],
// [ [11], [12], [15], [16]]]
//
// ```
//
// Arguments:
//
// block_size: The size of the spatial block, same as in Space2Depth.
func DepthToSpace(scope *Scope, input tf.Output, block_size int64) (output tf.Output) {
if scope.Err() != nil {
return
}
attrs := map[string]interface{}{"block_size": block_size}
opspec := tf.OpSpec{
Type: "DepthToSpace",
Input: []tf.Input{
input,
},
Attrs: attrs,
}
op := scope.AddOperation(opspec)
return op.Output(0)
}
// BatchToSpace for N-D tensors of type T.
//
// This operation reshapes the "batch" dimension 0 into `M + 1` dimensions of shape
// `block_shape + [batch]`, interleaves these blocks back into the grid defined by
// the spatial dimensions `[1, ..., M]`, to obtain a result with the same rank as
// the input. The spatial dimensions of this intermediate result are then
// optionally cropped according to `crops` to produce the output. This is the
// reverse of SpaceToBatch. See below for a precise description.
//
// Arguments:
// input: N-D with shape `input_shape = [batch] + spatial_shape + remaining_shape`,
// where spatial_shape has M dimensions.
// block_shape: 1-D with shape `[M]`, all values must be >= 1.
// crops: 2-D with shape `[M, 2]`, all values must be >= 0.
// `crops[i] = [crop_start, crop_end]` specifies the amount to crop from input
// dimension `i + 1`, which corresponds to spatial dimension `i`. It is
// required that
// `crop_start[i] + crop_end[i] <= block_shape[i] * input_shape[i + 1]`.
//
// This operation is equivalent to the following steps:
//
// 1. Reshape `input` to `reshaped` of shape:
// [block_shape[0], ..., block_shape[M-1],
// batch / prod(block_shape),
// input_shape[1], ..., input_shape[N-1]]
//
// 2. Permute dimensions of `reshaped` to produce `permuted` of shape
// [batch / prod(block_shape),
//
// input_shape[1], block_shape[0],
// ...,
// input_shape[M], block_shape[M-1],
//
// input_shape[M+1], ..., input_shape[N-1]]
//
// 3. Reshape `permuted` to produce `reshaped_permuted` of shape
// [batch / prod(block_shape),
//
// input_shape[1] * block_shape[0],
// ...,
// input_shape[M] * block_shape[M-1],
//
// input_shape[M+1],
// ...,
// input_shape[N-1]]
//
// 4. Crop the start and end of dimensions `[1, ..., M]` of
// `reshaped_permuted` according to `crops` to produce the output of shape:
// [batch / prod(block_shape),
//
// input_shape[1] * block_shape[0] - crops[0,0] - crops[0,1],
// ...,
// input_shape[M] * block_shape[M-1] - crops[M-1,0] - crops[M-1,1],
//
// input_shape[M+1], ..., input_shape[N-1]]
//
// Some examples:
//
// (1) For the following input of shape `[4, 1, 1, 1]`, `block_shape = [2, 2]`, and
// `crops = [[0, 0], [0, 0]]`:
//
// ```prettyprint
// [[[[1]]], [[[2]]], [[[3]]], [[[4]]]]
// ```
//
// The output tensor has shape `[1, 2, 2, 1]` and value:
//
// ```prettyprint
// x = [[[[1], [2]], [[3], [4]]]]
// ```
//
// (2) For the following input of shape `[4, 1, 1, 3]`, `block_shape = [2, 2]`, and
// `crops = [[0, 0], [0, 0]]`:
//
// ```prettyprint
// [[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]], [[10, 11, 12]]]
// ```
//
// The output tensor has shape `[1, 2, 2, 3]` and value:
//
// ```prettyprint
// x = [[[[1, 2, 3], [4, 5, 6]],
// [[7, 8, 9], [10, 11, 12]]]]
// ```
//
// (3) For the following input of shape `[4, 2, 2, 1]`, `block_shape = [2, 2]`, and
// `crops = [[0, 0], [0, 0]]`:
//
// ```prettyprint
// x = [[[[1], [3]], [[9], [11]]],
// [[[2], [4]], [[10], [12]]],
// [[[5], [7]], [[13], [15]]],
// [[[6], [8]], [[14], [16]]]]
// ```
//
// The output tensor has shape `[1, 4, 4, 1]` and value:
//
// ```prettyprint
// x = [[[1], [2], [3], [4]],
// [[5], [6], [7], [8]],
// [[9], [10], [11], [12]],
// [[13], [14], [15], [16]]]
// ```
//
// (4) For the following input of shape `[8, 1, 3, 1]`, `block_shape = [2, 2]`, and
// `crops = [[0, 0], [2, 0]]`:
//
// ```prettyprint
// x = [[[[0], [1], [3]]], [[[0], [9], [11]]],
// [[[0], [2], [4]]], [[[0], [10], [12]]],
// [[[0], [5], [7]]], [[[0], [13], [15]]],
// [[[0], [6], [8]]], [[[0], [14], [16]]]]
// ```
//
// The output tensor has shape `[2, 2, 4, 1]` and value:
//
// ```prettyprint
// x = [[[[1], [2], [3], [4]],
// [[5], [6], [7], [8]]],
// [[[9], [10], [11], [12]],
// [[13], [14], [15], [16]]]]
// ```
func BatchToSpaceND(scope *Scope, input tf.Output, block_shape tf.Output, crops tf.Output) (output tf.Output) {
if scope.Err() != nil {
return
}
opspec := tf.OpSpec{
Type: "BatchToSpaceND",
Input: []tf.Input{
input, block_shape, crops,
},
}
op := scope.AddOperation(opspec)
return op.Output(0)
}
// SpaceToBatch for 4-D tensors of type T.
//
// This is a legacy version of the more general SpaceToBatchND.
//
// Zero-pads and then rearranges (permutes) blocks of spatial data into batch.
// More specifically, this op outputs a copy of the input tensor where values from
// the `height` and `width` dimensions are moved to the `batch` dimension. After
// the zero-padding, both `height` and `width` of the input must be divisible by the
// block size.
//
// Arguments:
// input: 4-D with shape `[batch, height, width, depth]`.
// paddings: 2-D tensor of non-negative integers with shape `[2, 2]`. It specifies
// the padding of the input with zeros across the spatial dimensions as follows:
//
// paddings = [[pad_top, pad_bottom], [pad_left, pad_right]]
//
// The effective spatial dimensions of the zero-padded input tensor will be:
//
// height_pad = pad_top + height + pad_bottom
// width_pad = pad_left + width + pad_right
//
// The attr `block_size` must be greater than one. It indicates the block size.
//
// * Non-overlapping blocks of size `block_size x block size` in the height and
// width dimensions are rearranged into the batch dimension at each location.
// * The batch of the output tensor is `batch * block_size * block_size`.
// * Both height_pad and width_pad must be divisible by block_size.
//
// The shape of the output will be:
//
// [batch*block_size*block_size, height_pad/block_size, width_pad/block_size,
// depth]
//
// Some examples:
//
// (1) For the following input of shape `[1, 2, 2, 1]` and block_size of 2:
//
// ```prettyprint
// x = [[[[1], [2]], [[3], [4]]]]
// ```
//
// The output tensor has shape `[4, 1, 1, 1]` and value:
//
// ```prettyprint
// [[[[1]]], [[[2]]], [[[3]]], [[[4]]]]
// ```
//
// (2) For the following input of shape `[1, 2, 2, 3]` and block_size of 2:
//
// ```prettyprint
// x = [[[[1, 2, 3], [4, 5, 6]],
// [[7, 8, 9], [10, 11, 12]]]]
// ```
//
// The output tensor has shape `[4, 1, 1, 3]` and value:
//
// ```prettyprint
// [[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]], [[10, 11, 12]]]
// ```
//
// (3) For the following input of shape `[1, 4, 4, 1]` and block_size of 2:
//
// ```prettyprint
// x = [[[[1], [2], [3], [4]],
// [[5], [6], [7], [8]],
// [[9], [10], [11], [12]],
// [[13], [14], [15], [16]]]]
// ```
//
// The output tensor has shape `[4, 2, 2, 1]` and value:
//
// ```prettyprint
// x = [[[[1], [3]], [[9], [11]]],
// [[[2], [4]], [[10], [12]]],
// [[[5], [7]], [[13], [15]]],
// [[[6], [8]], [[14], [16]]]]
// ```
//
// (4) For the following input of shape `[2, 2, 4, 1]` and block_size of 2:
//
// ```prettyprint
// x = [[[[1], [2], [3], [4]],
// [[5], [6], [7], [8]]],
// [[[9], [10], [11], [12]],
// [[13], [14], [15], [16]]]]
// ```
//
// The output tensor has shape `[8, 1, 2, 1]` and value:
//
// ```prettyprint
// x = [[[[1], [3]]], [[[9], [11]]], [[[2], [4]]], [[[10], [12]]],
// [[[5], [7]]], [[[13], [15]]], [[[6], [8]]], [[[14], [16]]]]
// ```
//
// Among others, this operation is useful for reducing atrous convolution into
// regular convolution.
//
func SpaceToBatch(scope *Scope, input tf.Output, paddings tf.Output, block_size int64) (output tf.Output) {
if scope.Err() != nil {
return
}
attrs := map[string]interface{}{"block_size": block_size}
opspec := tf.OpSpec{
Type: "SpaceToBatch",
Input: []tf.Input{
input, paddings,
},
Attrs: attrs,
}
op := scope.AddOperation(opspec)
return op.Output(0)
}
// QuantizeAndDequantizeV2Attr is an optional argument to QuantizeAndDequantizeV2.
type QuantizeAndDequantizeV2Attr func(optionalAttr)
// QuantizeAndDequantizeV2SignedInput sets the optional signed_input attribute to value.
//
// value: If the quantization is signed or unsigned.
// If not specified, defaults to true
func QuantizeAndDequantizeV2SignedInput(value bool) QuantizeAndDequantizeV2Attr {
return func(m optionalAttr) {
m["signed_input"] = value
}
}
// QuantizeAndDequantizeV2NumBits sets the optional num_bits attribute to value.
//
// value: The bitwidth of the quantization.
// If not specified, defaults to 8
func QuantizeAndDequantizeV2NumBits(value int64) QuantizeAndDequantizeV2Attr {
return func(m optionalAttr) {
m["num_bits"] = value
}
}
// QuantizeAndDequantizeV2RangeGiven sets the optional range_given attribute to value.
//