Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementation of tf.extract_image_patches

Where is the implementation of tf.extract_image_patches? I checked the tensorflow repository I could not find it.

The file tensorflow/core/kernels/extract_image_patches_op.cc does not contain an implementation.

like image 406
GDG Avatar asked Mar 08 '23 18:03

GDG


1 Answers

That's an interesting question. The path is as follows:

  • Python tf.extract_image_patches function is implemented in the generated file tensorflow/python/ops/gen_array_ops.py, which invokes "ExtractImagePatches" native op.

  • This op is implemented by ExtractImagePatchesOp in core/kernels/extract_image_patches_op.cc for both CPU and GPU devices. The main call is functor::ExtractImagePatchesForward...

  • ... which is defined in core/kernels/extract_image_patches_op.h. The actual logic is delegated to the ::extract_image_patches() method of the input tensor. The tensor's type is TTypes<T, 4>::ConstTensor, which is a typedef of Eigen::TensorMap core/framework/tensor_types.h.

At this point, it's getting out of tensorflow source base, because Eigen is from the third-party eigen library (GitHub mirror). Its source code is somewhat non-trivially downloaded and linked to tensorflow, but right now we are interested in Eigen::TensorMap::extract_image_patches() function.

  • It's defined in eigen/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h file and applies TensorImagePatchOp...

  • ... which can be found in eigen/unsupported/Eigen/CXX11/src/Tensor/TensorImagePatch.h. Finally, this functor doesn't delegate it further, i.e. the actual implementation.

Note that particular version of Eigen library may be different in different builds of tensorflow, which you should check in the bazel config.

like image 175
Maxim Avatar answered Mar 31 '23 10:03

Maxim