Coder Social home page Coder Social logo

Comments (10)

anuragranj avatar anuragranj commented on August 15, 2024 1

Actually, we want to warp image2 to image1 given the optical flow. The warping here is also called inverse warping. Here is why this is better (slides 1-6): https://www.cs.unc.edu/~lazebnik/research/fall08/lec08_faces.pdf

from spynet.

EnQing626 avatar EnQing626 commented on August 15, 2024 1

@anuragranj Very thanks for your replying. It helps me to understand warping and inverse warping better.

from spynet.

anuragranj avatar anuragranj commented on August 15, 2024

The files in extra implement two layers:

  1. warping: this can be implemented using pytorch/torch.nn.functional.grid_sample. Note that spynet's warping takes optical flow (u,v) as input, and grid_sample takes (2((x+u)/w -0.5), 2((y+v)/h -0.5)) as input, where (w,h) are the image width and height, and (x,y) are the image coordinates. So you would need to scale the flows accordingly while using grid_sample.
  2. Scale: This can be implemented as bilinear upsampling using pytorch/torch.nn.function.upsample(mode='bilinear')

from spynet.

anuragranj avatar anuragranj commented on August 15, 2024

This is equivalent flow warper in pytorch.

class FlowWarper(nn.Module):
    def __init__(self):
        super(FlowWarper, self).__init__(w,h)
        x = np.arange(0,w)
        y = np.arange(0,h)
        gx, gy = np.meshgrid(x,y)
        self.w = w
        self.h = h
        self.grid_x = Variable(torch.Tensor(gx), requires_grad=False)
        self.grid_y = Variable(torch.Tensor(gy), requires_grad=False)

    def forward(self, img, uv):
        u = uv[:,0,:,:]
        v = uv[:,1,:,:]
        X = self.grid_x.unsqueeze(0).expand_as(u) + u
        Y = self.grid_y.unsqueeze(0).expand_as(v) + v
        X = 2*(X/self.w - 0.5)
        Y = 2*(Y/self.h - 0.5)
        grid_tf = torch.stack((X,Y), dim=3)
        img_tf = F.grid_sample(img, grid_tf)
        return img_tf

from spynet.

sniklaus avatar sniklaus commented on August 15, 2024

You may also have a look at: https://github.com/sniklaus/pytorch-spynet

Thank you Anurag for you great work!

from spynet.

PkuRainBow avatar PkuRainBow commented on August 15, 2024

@sniklaus Great! I am wondering could you share your reproduced performance?

from spynet.

sniklaus avatar sniklaus commented on August 15, 2024

All necessary code is in the linked repository, what do you need in particular?

from spynet.

anuragranj avatar anuragranj commented on August 15, 2024

Thanks @sniklaus for the pytorch version.

from spynet.

PkuRainBow avatar PkuRainBow commented on August 15, 2024

@sniklaus Thanks. Nothing particular is needed.

from spynet.

EnQing626 avatar EnQing626 commented on August 15, 2024

hi @anuragranj , It seems that if you want to warp an image from image1 to image2 and the optical flow is generated from image1 to image2, you should set "u = -uv[:,0,:,:] and v = -uv[:,1,:,:]" instead of "u = uv[:,0,:,:] v = uv[:,1,:,:]". Is that correct?

from spynet.

Related Issues (19)

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.