1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CORE_KERNELS_IMAGECROP_AND_RESIZE_OP_H_ 17 #define TENSORFLOW_CORE_KERNELS_IMAGECROP_AND_RESIZE_OP_H_ 18 19 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" 20 #include "tensorflow/core/framework/numeric_types.h" 21 #include "tensorflow/core/framework/op_kernel.h" 22 #include "tensorflow/core/framework/tensor_types.h" 23 24 namespace tensorflow { 25 namespace functor { 26 27 template <typename Device, typename T> 28 struct CropAndResize { 29 // We assume that the tensor sizes are correct. 30 bool operator()(const OpKernelContext* context, 31 typename TTypes<T, 4>::ConstTensor image, 32 typename TTypes<float, 2>::ConstTensor boxes, 33 typename TTypes<int32, 1>::ConstTensor box_ind, 34 const std::string& method_name, float extrapolation_value, 35 typename TTypes<float, 4>::Tensor crops); 36 }; 37 38 template <typename Device, typename T> 39 struct CropAndResizeBackpropImage { 40 // We assume that the tensor sizes are correct. 41 bool operator()(const OpKernelContext* context, 42 typename TTypes<float, 4>::ConstTensor grads, 43 typename TTypes<float, 2>::ConstTensor boxes, 44 typename TTypes<int32, 1>::ConstTensor box_ind, 45 typename TTypes<T, 4>::Tensor grads_image, 46 const std::string& method_name); 47 }; 48 49 template <typename Device, typename T> 50 struct CropAndResizeBackpropBoxes { 51 // We assume that the tensor sizes are correct. 52 bool operator()(const Device& d, typename TTypes<float, 4>::ConstTensor grads, 53 typename TTypes<T, 4>::ConstTensor image, 54 typename TTypes<float, 2>::ConstTensor boxes, 55 typename TTypes<int32, 1>::ConstTensor box_ind, 56 typename TTypes<float, 2>::Tensor grads_boxes); 57 }; 58 59 template <typename Device> 60 struct CheckValidBoxIndexHelper { 61 // Checks if all values in box_index are in [0, batch). operatorCheckValidBoxIndexHelper62 void operator()(const Device& d, 63 typename TTypes<int32, 1>::ConstTensor box_index, int batch, 64 typename TTypes<bool, 0>::Tensor isvalid) { 65 isvalid.device(d) = ((box_index >= 0) && (box_index < batch)).all(); 66 } 67 }; 68 69 } // namespace functor 70 } // namespace tensorflow 71 72 #endif // TENSORFLOW_CORE_KERNELS_IMAGECROP_AND_RESIZE_OP_H_ 73