Code Monkey home page Code Monkey logo

pytorch-trilinear-interpolation's Introduction

PyTorch-Trilinear-Interpolation

Example Usage

import torch
from interpolation import TrilinearIntepolation
batch_size, width, height, depth = 1, 128, 128, 32
num_channels = 32
# Input data
input_data = torch.rand(batch_size, num_channels, depth, height, width).float()
sampling_grid = (torch.rand(batch_size, height, width, 3) - 0.5)*2.0

# create interpolation layer
trilinear_interpolation = TrilinearIntepolation()
# apply_interpolation
interpolated_data = trilinear_interpolation(input_data, sampling_grid)
print(interpolated_data.shape)

pytorch-trilinear-interpolation's People

Contributors

tedyhabtegebrial avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

elientumba2019

pytorch-trilinear-interpolation's Issues

Trilinear interpolation from grid to point cloud - New feature request

Suppose I have a uniformly spaced grid with some optional features and I need to interpolate those to a point cloud (non uniformly spaced). This should be the opposite of your code:
For example (1D) going from 0, 1, 2, 3 to the non uniform points 0.1, 0.8, 1.3, 1.8

Would it be possible with some modification of the code?

Thanks
Cheers

Exception when sampling_grid and input_data has different height and width.

Hi when i try to use TrilinearIntepolation layer for sampling_grid and input_data with different height and width I get exception. Please take a look to a small reproducible example.

batch_size, width, height, depth = 1, 128, 128, 32
num_channels = 32
# Input data
input_data = torch.rand(batch_size, num_channels, depth, height, width).float()
sampling_grid = (torch.rand(batch_size, 256, 256, 3) - 0.5)*2.0

# create interpolation layer
trilinear_interpolation = TrilinearIntepolation()
# apply_interpolation
interpolated_data = trilinear_interpolation(input_data, sampling_grid)
print(interpolated_data.shape)

Exception stack trace:

Traceback (most recent call last):
  File "temp5.py", line 78, in <module>
    interpolated_data = trilinear_interpolation(input_data, sampling_grid)
  File "site-packages\torch\nn\modules\module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "temp5.py", line 50, in forward
    batch_size, num_chans, height, width),  [u, v, w])
  File "temp5.py", line 49, in <lambda>
    u, v, w = map(lambda x:x.view(batch_size, 1, height, width).expand(
RuntimeError: shape '[1, 1, 128, 128]' is invalid for input of size 65536

F.grid_sample behaviour changed after torch 1.3.0

The baviour of F.grid_sample has changed after torch 1.3.0, please add one argument to this line

# before
sampled_in_2d = F.grid_sample(input=input_feats.view(batch_size, num_chans * num_d, height, width),
                                      grid=xy_grid, mode='nearest').view(batch_size, num_chans, num_d, grid_height,
                                                                         grid_width)

# after
sampled_in_2d = F.grid_sample(input=input_feats.view(batch_size, num_chans * num_d, height, width),
                                      grid=xy_grid, mode='nearest', align_corners=True).view(batch_size, num_chans, num_d, grid_height,
                                                                         grid_width)

You can use this simple example to test

from interpolation import TrilinearIntepolation
import torch

if __name__ == "__main__":
    batch = 1
    feature_channel_num = 1
    data_points = torch.tensor([1., 2., 3., 4., 5., 6., 7., 8.]).reshape(batch, feature_channel_num, 2, 2, 2)
    sample_point_pos = torch.tensor([
        [0., 0., 0.],
        [1., 0., 0.],
        [0., 1., 0.],
        [1., 1., 0.],
        [0., 0., 1.],
        [1., 0., 1.],
        [0., 1., 1.],
        [1., 1., 1.],
    ]).reshape(batch, 4, 2, 3) * 2.0 - 1.0
    trilinear_interpolation = TrilinearIntepolation()
    output = trilinear_interpolation(data_points, sample_point_pos)
    print(output)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.