Code Monkey home page Code Monkey logo

Comments (10)

fepegar avatar fepegar commented on August 24, 2024 1

I think the code logic is correct, but maybe the docs and the error message are not clear. The idea is that a single scale value for all dimensions is sampled if isotropic is True. The number of scales must be one or two because if it's one (let's call it $s$, the min and max along all dimensions will be $[1-s, 1+s]$. If it's two, the values will be the min and max scale. If it's three, it's the former case for each dimension, and six means the latter for each dimension.

Does that make sense?

from torchio.

arsalanfiroozi avatar arsalanfiroozi commented on August 24, 2024

I have the same issue.

from torchio.

romainVala avatar romainVala commented on August 24, 2024

Hello
I aggree it seems a bug to fix, but the work-around seems quite easy
either set the scale with 3 number, but put isotropic to False
or just set cale with 1 number (since you want it to be isotropic). In this case you do not even need to set the "isotropic" argument (default False will also be fine). (should work exactly the same with issotropic set to True)

May be I miss something, (@fepegar ?) but my understanding is that "isotropic" argument is not usefull

from torchio.

AminAlam avatar AminAlam commented on August 24, 2024

Hi and thanks for your response. I agree that there are workarounds for this bug, but I believe it's better to fix it. I fixed it in this pull request using a single line of code #1159

from torchio.

romainVala avatar romainVala commented on August 24, 2024

hmm, the logic I do not understand is when is the isotropic argument necessary ? My understanding is that isotropic is implicit when you specify parameter of length 1 or 2

taff1 = tio.RandomAffine(scales=0.2)
taff2 = tio.RandomAffine(scales=(0.8, 1.5))

print(f'Scale is {taff1.scales}   isotropic is {taff1.isotropic} ')
print(f'Scale is {taff2.scales}   isotropic is {taff2.isotropic} ')
Scale is (0.8, 1.2, 0.8, 1.2, 0.8, 1.2)   isotropic is False 
Scale is (0.8, 1.5, 0.8, 1.5, 0.8, 1.5)   isotropic is False 

from torchio.

AminAlam avatar AminAlam commented on August 24, 2024

Thanks @fepegar, it makes sense to me now. I have modified the error message and the documentation to make it more clear. Please find them in this #1163.

@romainVala Based on this code in spatial.radom_affine.RandomAffien.get_params:

scaling_params = self.sample_uniform_sextet(scales)
  if isotropic:
      scaling_params.fill_(scaling_params[0])

If "isotropic" is True, then the scaling factor of all other dimensions is filled with the first scaling factor, so when "scales" only has 1 or 2 values and "isotropic" is set as True, we make sure that all dimensions will be scaled with the same factor. In your example, the values of scales are lower and upper bounds of random sampling, not the actual values of scaling in the transformation.

from torchio.

romainVala avatar romainVala commented on August 24, 2024

not sure to understand properly ...
scale input parameter for RandomAffine is to specify the lower and upper bound ... in order to do a random selection.
If you want to force RandomAffine to get a specific value (for instance 0.8), then you need to restrict the bound to (0.8, 0.8) ... or may be, since you do not want randomness, then directly go with the Affine transform

I agree with the code snipet you show, but my example demonstrate that this line of code is not needed.

from torchio.

AminAlam avatar AminAlam commented on August 24, 2024

@romainVala Imagine that we have set the bounds as (1,3), then the scales will be randomly selected as (1.3, 1.5, 2.8). If "isotropic" is True, then we force the scales to be (1.3, 1.3, 1.3). The scaling factor is chosen randomly but as isotropic is True, it will be same for all dimensions.

from torchio.

fepegar avatar fepegar commented on August 24, 2024

@AminAlam, that's the intended behavior indeed.

from torchio.

romainVala avatar romainVala commented on August 24, 2024

Ok, my bad
I was too focus on the extension of input parameter, But you are right
isotropic is for enforcing the chosen random values to be isotropic
sorry for my confusions

from torchio.

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.