imedslab / solt

Streaming over lightweight data transformations
https://oulu-imeds.github.io/solt/
MIT License
264 stars 19 forks source link

Requesting additional accepted type 'list' to support reading from yaml-file #79

Closed aisosalo closed 2 years ago

aisosalo commented 2 years ago

It would good to have list as accepted type here to support reading from yaml-file.

lext commented 2 years ago

Doesn't it work already if you use from_yaml? https://oulu-imeds.github.io/solt/utils.html#solt.utils.from_yaml

aisosalo commented 2 years ago

For the transform resize I am getting the following error message when reading the attached transformation stream:

>> solt.__version__
'0.1.9'
>> solt.utils.from_yaml('trf.yaml')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/user/anaconda3/envs/py37_env/lib/python3.7/site-packages/solt/utils/_utils.py", line 171, in from_yaml
    return from_dict(d)
  File "/home/user/anaconda3/envs/py37_env/lib/python3.7/site-packages/solt/utils/_utils.py", line 112, in from_dict
    transforms[t]["transforms"] = [from_dict(x) for x in transforms[t]["transforms"]]
  File "/home/user/anaconda3/envs/py37_env/lib/python3.7/site-packages/solt/utils/_utils.py", line 112, in <listcomp>
    transforms[t]["transforms"] = [from_dict(x) for x in transforms[t]["transforms"]]
  File "/home/user/anaconda3/envs/py37_env/lib/python3.7/site-packages/solt/utils/_utils.py", line 120, in from_dict
    return cls(**transforms[t])
  File "/home/user/anaconda3/envs/py37_env/lib/python3.7/site-packages/solt/transforms/_transforms.py", line 635, in __init__
    raise TypeError("The argument resize_to has an incorrect type!")
TypeError: The argument resize_to has an incorrect type!

Perhaps I am doing something wrong?

Transformation stream (resulting originally from print(stream.to_yaml()) with codes &id001 and *id001 commented out):

stream:
  ignore_fast_mode: false
  interpolation: null
  optimize_stack: false
  padding: null
  transforms:
  - resize:
      interpolation:
      - bilinear
      - inherit
      resize_to: #&id001
      - 1920
      - 2944
  - projection:
      affine_transforms:
        stream:
          ignore_fast_mode: false
          interpolation: null
          optimize_stack: false
          padding: null
          transforms:
          - rotate:
              angle_range:
              - -3
              - 3
              ignore_fast_mode: false
              ignore_state: true
              interpolation:
              - bilinear
              - inherit
              p: 0.5
              padding:
              - z
              - inherit
          - scale:
              ignore_fast_mode: false
              ignore_state: true
              interpolation:
              - bilinear
              - inherit
              p: 0.5
              padding:
              - z
              - inherit
              range_x:
              - 0.6
              - 1.4
              range_y:
              - 0.6
              - 1.4
              same: false
          - shear:
              ignore_fast_mode: false
              ignore_state: true
              interpolation:
              - bilinear
              - inherit
              p: 0.5
              padding:
              - z
              - inherit
              range_x:
              - -0.6
              - 0.6
              range_y:
              - -0.6
              - 0.6
          - translate:
              ignore_fast_mode: false
              ignore_state: true
              interpolation:
              - bilinear
              - inherit
              p: 0.5
              padding:
              - z
              - inherit
              range_x:
              - -50
              - 50
              range_y:
              - -50
              - 50
      ignore_fast_mode: false
      ignore_state: true
      interpolation:
      - bilinear
      - inherit
      p: 0.5
      padding:
      - z
      - inherit
  - pad:
      pad_to: #*id001
      - 1920
      - 2944
      padding:
      - z
      - inherit
  - crop:
      crop_mode: r
  - flip:
      axis: 1
      data_indices: null
      p: 0.5
  - selective_stream:
      ignore_fast_mode: false
      n: 1
      optimize_stack: false
      probs: null
      transforms:
      - cutout:
          cutout_size:
          - 384
          - 588
          data_indices: null
          p: 0.5
  - selective_stream:
      ignore_fast_mode: false
      n: 1
      optimize_stack: false
      probs: null
      transforms:
      - noise:
          data_indices: null
          gain_range:
          - 0
          - 0.1
          p: 0.5
      - selective_stream:
          ignore_fast_mode: false
          n: 1
          optimize_stack: false
          probs: null
          transforms:
          - blur:
              data_indices: null
              gaussian_sigma:
              - 1
              - 2
              k_size:
              - 3
              - 7
              - 11
              p: 0.5
lext commented 2 years ago

This test passes: https://github.com/Oulu-IMEDS/solt/blob/fae62de9ba98f9213ab323cb56c64145ac20e2c2/tests/test_utils.py#L247. Can you try to localize the bug?

lext commented 2 years ago

I think I have found the bug. The fixed version is now in master.