batchgenerators icon indicating copy to clipboard operation
batchgenerators copied to clipboard

code segment about scale

Open HeConnor opened this issue 4 months ago • 0 comments

Hi,

I have a question about the "scale"; the following code segment:

if do_scale and np.random.uniform() < p_scale_per_sample:
   if independent_scale_for_each_axis and np.random.uniform() < p_independent_scale_per_axis:
       sc = []
       for _ in range(dim):
           if np.random.random() < 0.5 and scale[0] < 1:
               sc.append(np.random.uniform(scale[0], 1))      #
           else:
               sc.append(np.random.uniform(max(scale[0], 1), scale[1]))
   else:
       if np.random.random() < 0.5 and scale[0] < 1:
           sc = np.random.uniform(scale[0], 1)
       else:
           sc = np.random.uniform(max(scale[0], 1), scale[1])

I'm confused and has this design considered other issues?

I think should the code be changed to this:

...
       for _ in range(dim):
           if np.random.random() < 0.5 and scale[0] < 1:
               sc.append(np.random.uniform(scale[0], min(scale[1], 1)))
           else:
               sc.append(np.random.uniform(max(scale[0], 1), scale[1]))
   else:
       if np.random.random() < 0.5 and scale[0] < 1:
           sc = np.random.uniform(scale[0], min(scale[1], 1))
       else:
           sc = np.random.uniform(max(scale[0], 1), scale[1])

Or more simplified:

if independent_scale_for_each_axis and np.random.uniform() < p_independent_scale_per_axis:
    sc = []
    for _ in range(dim):
        sc.append(np.random.uniform(scale[0], scale[1]))
else:
    sc = np.random.uniform(scale[0], scale[1])

Best regards, Connor

HeConnor avatar Nov 10 '25 08:11 HeConnor