Git Product home page Git Product logo

Comments (11)

bearpaw avatar bearpaw commented on August 25, 2024 1

@sydney0zq This is the matrix for the affine transform. You may learn the relevant knowledge from image processing or computer vision courses.

@xiaoyong Actually I am a little bit confused about this 1 to 0 index from lua to torch (and from the annotation). Would you create a pull request to clarify this if it won't cost much of your time? Thank you very much!

from pytorch-pose.

bestlin avatar bestlin commented on August 25, 2024

from pytorch-pose.

zhiqiangdon avatar zhiqiangdon commented on August 25, 2024

Hi @bestlin ,

I know that python's index starts from 0 while lua index starts from 1. I don't think this is the reason. Because the index difference should considered in the data preprocessing part, i.e. generating the json files. A more important reason is that minus 1 at the resolution of 64x64 and plus 1 at the resolution of 256x256 is obviously not equivalent not matter in python or lua.

from pytorch-pose.

bearpaw avatar bearpaw commented on August 25, 2024

For transform, please refer to the original lua code.
https://github.com/anewell/pose-hg-train/blob/master/src/util/img.lua#L54-L65

function transform(pt, center, scale, rot, res, invert)
    local pt_ = torch.ones(3)
    pt_[1],pt_[2] = pt[1]-1,pt[2]-1

    local t = getTransform(center, scale, rot, res)
    if invert then
        t = torch.inverse(t)
    end
    local new_point = (t*pt_):sub(1,2)

    return new_point:int():add(1)
end

The +1 and -1 in the following code is left here for historical reason. To compare with previously trained models, I will leave them unchanged.

tpts[i, 0:2] = to_torch(transform(tpts[i, 0:2]+1, c, s, [self.out_res, self.out_res], rot=r))
target[i] = draw_labelmap(target[i], tpts[i]-1, self.sigma, type=self.label_type)

from pytorch-pose.

zhiqiangdon avatar zhiqiangdon commented on August 25, 2024

@bearpaw ,Thanks! I was reading the file in repo pose-hg-demo:
https://github.com/anewell/pose-hg-demo/blob/master/img.lua

function transform(pt, center, scale, rot, res, invert)
-- For managing coordinate transformations between the original image space
-- and the heatmap

local pt_ = torch.ones(3)
pt_[1] = pt[1]
pt_[2] = pt[2]
local t = getTransform(center, scale, rot, res)
if invert then
    t = torch.inverse(t)
end
local new_point = (t*pt_):sub(1,2):int()
return new_point

end

Do you know why doesn't this transform function have the +1 and -1? Thanks!

from pytorch-pose.

bearpaw avatar bearpaw commented on August 25, 2024

@zhiqiangdon It seems that there are some mismatches between pose-hg-demo and pose-hg-train. I think pose-hg-train is relatively up-to-date.

I do not quite know the reason. But I guess it might due to the int operation. The trick might improve the computational accuracy (float and int stuff) and the performance a little bit. But it's absolutely not a key point, and I've never verified this either.

from pytorch-pose.

zhiqiangdon avatar zhiqiangdon commented on August 25, 2024

@bearpaw Thanks!

from pytorch-pose.

sydney0zq avatar sydney0zq commented on August 25, 2024

I have some questions about transform.py, can anyone help me out?

def get_transform(center, scale, res, rot=0):
    # General image processing matrix
    h = 200 * scale     # what does 200 means?
    t = np.zeros((3, 3)) # this is transform matrix, what is our aim? Any mathematical formula?
    t[0, 0] = float(res[1]) / h
    t[1, 1] = float(res[0]) / h
    t[0, 2] = res[1] * (-float(center[0]) / h + .5)
    t[1, 2] = res[0] * (-float(center[1]) / h + .5)
    t[2, 2] = 1   

Thanks, I just get stuck on them.

from pytorch-pose.

xiaoyong avatar xiaoyong commented on August 25, 2024

Affine transform should be performed on 0-indexed points. So it's totally fine to remove the +1/-1 in transform and use consistent (0-indexed) coordinates.

@bearpaw There might exist an inconsistency in

ul = np.array(transform([0, 0], center, scale, res, invert=1))
# Bottom right point
br = np.array(transform(res, center, scale, res, invert=1))

where 0-indexed points are fed to transform but it expects 1-indexed points.

from pytorch-pose.

xiaoyong avatar xiaoyong commented on August 25, 2024

@bearpaw Sure, I converted 1 to 0 index and everything works well, both on your pretrained model and my own retrained model. But I need to do some code tidy up. Maybe after the forthcoming holiday :-)

from pytorch-pose.

nitba avatar nitba commented on August 25, 2024

Hi @xiaoyong ,

Can you show where in codes you omit +1 and -1 approach, and no results are changed
there are done because of converting float numbers to int somewhere

from pytorch-pose.

Related Issues (20)

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.