Does sparse_image_warp (from TF) exist in Pytorch?

username: zachc
cooked: <p>Hello,</p>
<p>PyTorch is great!</p>
<p>I’m not an image/vision expert and I’m looking for a function analogous to <a href="https://www.tensorflow.org/versions/r1.9/api_docs/python/tf/contrib/image/sparse_image_warp?hl=en" rel="nofollow noopener">sparse_image_warp</a> from TensorFlow, but in Pytorch. Does anyone know if it it exists?</p>
<p>Closest candidates I’ve found that don’t quite match:</p>
<ul>
<li><a href="https://torchgeometry.readthedocs.io/en/latest/_modules/torchgeometry/core/homography_warper.html" rel="nofollow noopener">Homography Warper</a></li>
</ul>
<p>Thanks a lot!</p>

username: liam.schoneveld
cooked: <p>Someone appears to have implemented it here:</p>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/zcaceres/spec_augment/blob/77335b74efc453c6bcd589357e8365ddcb7688aa/exp/nb_SparseImageWarp.py" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/zcaceres/spec_augment/blob/77335b74efc453c6bcd589357e8365ddcb7688aa/exp/nb_SparseImageWarp.py" target="_blank" rel="nofollow noopener">zcaceres/spec_augment/blob/77335b74efc453c6bcd589357e8365ddcb7688aa/exp/nb_SparseImageWarp.py</a></h4>
<pre><code class="lang-py">
#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: dev_nb/SparseImageWarp.ipynb

import torch
import numpy as np

def sparse_image_warp(img_tensor,
                      source_control_point_locations,
                      dest_control_point_locations,
                      interpolation_order=2,
                      regularization_weight=0.0,
                      num_boundaries_points=0):
    control_point_flows = (dest_control_point_locations - source_control_point_locations)

#     clamp_boundaries = num_boundary_points &gt; 0
#     boundary_points_per_edge = num_boundary_points - 1
    batch_size, image_height, image_width = img_tensor.shape
</code></pre>

  This file has been truncated. <a href="https://github.com/zcaceres/spec_augment/blob/77335b74efc453c6bcd589357e8365ddcb7688aa/exp/nb_SparseImageWarp.py" target="_blank" rel="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>See also:<br>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/zcaceres/spec_augment/blob/77335b74efc453c6bcd589357e8365ddcb7688aa/SparseImageWarp.ipynb" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/zcaceres/spec_augment/blob/77335b74efc453c6bcd589357e8365ddcb7688aa/SparseImageWarp.ipynb" target="_blank" rel="nofollow noopener">zcaceres/spec_augment/blob/77335b74efc453c6bcd589357e8365ddcb7688aa/SparseImageWarp.ipynb</a></h4>
<pre><code class="lang-ipynb">{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# TensorFlow's `sparse_image_warp` in Pytorch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [],
   "source": [
    "# first call `%store spectro` in the other notebook to save spectro value here\n",
    "%store -r spectro"
   ]
  },
  {
</code></pre>

  This file has been truncated. <a href="https://github.com/zcaceres/spec_augment/blob/77335b74efc453c6bcd589357e8365ddcb7688aa/SparseImageWarp.ipynb" target="_blank" rel="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
</p>

username: zachc
cooked: <p>Thanks, that’s actually me <img src="/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: liam.schoneveld
cooked: <p>Aha, well great job and thank you! Have found this spec augmentation stuff to be useful</p>

username: taogelose
cooked: <p>It seems that the code post by <a class="mention" href="/u/liam.schoneveld">@liam.schoneveld</a> can only deal with one channel image, which is used to augment speech data. I am wondering where can I find the code to tackle color image (Maybe I can simply add a dimension in the code?)</p>

username: bnehoran
cooked: <p>The closest analog in PyTorch is <a href="https://pytorch.org/docs/stable/nn.functional.html#grid-sample" rel="nofollow noopener"><code>torch.nn.functional.grid_sample()</code></a>, but this is actually closer to the <code>dense_image_warp</code> function.</p>
<p>The conventions for the grid are also slightly different in PyTorch, but you can probably do a conversion to fit your needs.</p>
<p>I hope this helps!</p>

username: gziz
cooked: <p>Did you find one? Thanks</p>

username: gziz
cooked: <p>Can you ellaborate a bit on this?</p>

username: Billy-ZTB
cooked: <p>You can refer to<br>
<a href="https://pydrobert-pytorch.readthedocs.io/en/latest/api/pydrobert/torch/functional.html#pydrobert.torch.functional.sparse_image_warp" class="inline-onebox" rel="noopener nofollow ugc">functional — pydrobert-pytorch documentation</a>  for the same function.The function in spec_augment: <a href="https://github.com/zcaceres/spec_augment/blob/77335b74efc453c6bcd589357e8365ddcb7688aa/SparseImageWarp.ipynb" class="inline-onebox" rel="noopener nofollow ugc">spec_augment/SparseImageWarp.ipynb at 77335b74efc453c6bcd589357e8365ddcb7688aa · zcaceres/spec_augment · GitHub</a>  is not working correctly.</p>