MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Compute

Method Compute

tensorflow/core/kernels/summary_image_op.cc:52–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50 }
51
52 void Compute(OpKernelContext* c) override {
53 const Tensor& tags = c->input(0);
54 const Tensor& tensor = c->input(1);
55 OP_REQUIRES(c, IsLegacyScalar(tags.shape()),
56 errors::InvalidArgument("Tags must be a scalar"));
57 OP_REQUIRES(c,
58 tensor.dims() == 4 &&
59 (tensor.dim_size(3) == 1 || tensor.dim_size(3) == 3 ||
60 tensor.dim_size(3) == 4),
61 errors::InvalidArgument(
62 "Tensor must be 4-D with last dim 1, 3, or 4, not ",
63 tensor.shape().DebugString()));
64 const string& base_tag = tags.scalar<tstring>()();
65
66 OP_REQUIRES(c,
67 tensor.dim_size(0) < (1LL << 31) &&
68 tensor.dim_size(1) < (1LL << 31) &&
69 tensor.dim_size(2) < (1LL << 31) &&
70 (tensor.dim_size(1) * tensor.dim_size(2)) < (1LL << 29),
71 errors::InvalidArgument("Tensor too large for summary ",
72 tensor.shape().DebugString()));
73
74 // The casts and h * w cannot overflow because of the limits above.
75 const int batch_size = static_cast<int>(tensor.dim_size(0));
76 const int h = static_cast<int>(tensor.dim_size(1));
77 const int w = static_cast<int>(tensor.dim_size(2));
78 const int hw = h * w; // Compact these two dims for simplicity
79 const int depth = static_cast<int>(tensor.dim_size(3));
80
81 OP_REQUIRES(c, hw > 0 && depth > 0,
82 errors::InvalidArgument(
83 "input tensor must have non-zero dims. Found: [",
84 batch_size, ", ", h, ", ", w, ", ", depth, "]."));
85
86 Summary s;
87 if (tensor.dtype() == DT_UINT8) {
88 // For uint8 input, no normalization is necessary
89 auto ith_image = [&tensor, batch_size, hw, depth](int i) {
90 auto values = tensor.shaped<uint8, 3>({batch_size, hw, depth});
91 return typename TTypes<uint8>::ConstMatrix(
92 &values(i, 0, 0), Eigen::DSizes<Eigen::DenseIndex, 2>(hw, depth));
93 };
94 OP_REQUIRES_OK(
95 c, AddImages(base_tag, batch_size, w, h, depth, ith_image, &s));
96 } else if (tensor.dtype() == DT_HALF) {
97 NormalizeAndAddImages<Eigen::half>(c, tensor, h, w, hw, depth, batch_size,
98 base_tag, &s);
99 } else if (tensor.dtype() == DT_FLOAT) {
100 NormalizeAndAddImages<float>(c, tensor, h, w, hw, depth, batch_size,
101 base_tag, &s);
102 } else { // tensor.dtype() = DT_DOUBLE
103 NormalizeAndAddImages<double>(c, tensor, h, w, hw, depth, batch_size,
104 base_tag, &s);
105 }
106
107 Tensor* summary_tensor = nullptr;
108 OP_REQUIRES_OK(c, c->allocate_output(0, TensorShape({}), &summary_tensor));
109 CHECK(SerializeToTString(s, &summary_tensor->scalar<tstring>()()));

Callers

nothing calls this directly

Calls 11

InvalidArgumentFunction · 0.85
AddImagesFunction · 0.85
SerializeToTStringFunction · 0.85
allocate_outputMethod · 0.80
TensorShapeClass · 0.50
inputMethod · 0.45
shapeMethod · 0.45
dimsMethod · 0.45
dim_sizeMethod · 0.45
DebugStringMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected