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
|
#include "tensorflow/core/framework/function.h"
#include "tensorflow/core/lib/core/errors.h"
namespace tensorflow {
typedef FunctionDefHelper FDH;
REGISTER_OP_NO_GRADIENT("Shape");
REGISTER_OP_NO_GRADIENT("Rank");
REGISTER_OP_NO_GRADIENT("Size");
Status ReshapeGrad(const AttrSlice& attrs, FunctionDef* g) {
// clang-format off
*g = FDH::Define(
// Arg defs
{"x: T", "shape: int32", "dy: T"},
// Ret val defs
{"dx: T", "dshape: int32"},
// Attr defs
{{"T: {float, double}"}},
// Nodes
{
{{"x_shape"}, "Shape", {"x"}, {{"T", "$T"}}},
{{"dx"}, "Reshape", {"dy", "x_shape"}, {{"T", "$T"}}},
{{"dshape"}, "ZerosLike", {"shape"}, {{"T", DT_INT32}}},
});
// clang-format on
return Status::OK();
}
REGISTER_OP_GRADIENT("Reshape", ReshapeGrad);
} // end namespace tensorflow
|