| 177 | |
| 178 | template <class T> |
| 179 | Status NormalizeAndAddImages(const Tensor& tensor, int max_images, int h, int w, |
| 180 | int hw, int depth, int batch_size, |
| 181 | const string& base_tag, Tensor bad_color_tensor, |
| 182 | Summary* s) { |
| 183 | // For float and half images, nans and infs are replaced with bad_color. |
| 184 | if (bad_color_tensor.dim_size(0) < depth) { |
| 185 | return errors::InvalidArgument( |
| 186 | "expected depth <= bad_color.size, got depth = ", depth, |
| 187 | ", bad_color.size = ", bad_color_tensor.dim_size(0)); |
| 188 | } |
| 189 | auto bad_color_full = bad_color_tensor.vec<uint8>(); |
| 190 | typename TTypes<uint8>::ConstVec bad_color(bad_color_full.data(), depth); |
| 191 | |
| 192 | // Float images must be scaled and translated. |
| 193 | Uint8Image image(hw, depth); |
| 194 | auto ith_image = [&tensor, &image, bad_color, batch_size, hw, depth](int i) { |
| 195 | auto tensor_eigen = tensor.template shaped<T, 3>({batch_size, hw, depth}); |
| 196 | typename TTypes<T>::ConstMatrix values( |
| 197 | &tensor_eigen(i, 0, 0), Eigen::DSizes<Eigen::DenseIndex, 2>(hw, depth)); |
| 198 | NormalizeFloatImage<T>(hw, depth, values, bad_color, &image); |
| 199 | return image; |
| 200 | }; |
| 201 | return AddImages(base_tag, max_images, batch_size, w, h, depth, ith_image, s); |
| 202 | } |
| 203 | |
| 204 | } // namespace |
| 205 |
nothing calls this directly
no test coverage detected