zachc
(Zach C)
April 25, 2019, 12:38am
1
Hello,
PyTorch is great!
I’m not an image/vision expert and I’m looking for a function analogous to sparse_image_warp from TensorFlow, but in Pytorch. Does anyone know if it it exists?
Closest candidates I’ve found that don’t quite match:
Thanks a lot!
1 Like
Someone appears to have implemented it here:
#################################################
### 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 > 0
# boundary_points_per_edge = num_boundary_points - 1
batch_size, image_height, image_width = img_tensor.shape
This file has been truncated. show original
See also:
{
"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"
]
},
{
This file has been truncated. show original
1 Like
zachc
(Zach C)
April 29, 2019, 3:09pm
3
Thanks, that’s actually me
Aha, well great job and thank you! Have found this spec augmentation stuff to be useful
1 Like
It seems that the code post by @liam.schoneveld 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?)
The closest analog in PyTorch is torch.nn.functional.grid_sample()
, but this is actually closer to the dense_image_warp
function.
The conventions for the grid are also slightly different in PyTorch, but you can probably do a conversion to fit your needs.
I hope this helps!
1 Like
gziz
(G Moreno)
March 9, 2023, 1:11am
8
Can you ellaborate a bit on this?