Skip to content

Automatic creation of terratorch iterate config from a terratorch config #28

Description

@paolofraccaro

One of the barriers of using terratorch iterate is the creation of a terratorch iterate config from a terratorch config. We should have an automatic script/function that does that.

Activity

  1. leotizzei commented on Jul 24, 2025

    @leotizzei
    Contributor

    Hi @paolofraccaro,

    I moved the script that you implemented to this directory. Then I refactored it for the following reasons :

    • fix some issues (e.g., missing fields)
    • integrate with click, a python CLI lib, which allows users to specify directory, template and output via terminal
    • improve documentation

    I documented how to run this script here.

    Caveats:

    • the refactored script generates the config file, but I have not tested this config file yet, because I don't have access to the datasets. But I tested against the files generated by your original script and they are very similar
    • it does not work with the terratorch config file located in terratorch repoterratorch/tests/resources/configs/. There is still room to make this script more generic, that is, so it works with different config files. It seems that current implementation works well for geobench_v2 examples.
  2. leotizzei commented on Aug 7, 2025

    @leotizzei
    Contributor

    this is the error message that I'm getting when I run tt-iterate using this config. I think we need to change the way this script sets task type

    [I 2025-08-06 15:44:31,039] A new study created in RDB with name: manufactured-finetune
    INFO: Seed set to 42
    [W 2025-08-06 15:44:32,190] Trial 0 failed with parameters: {'lr': 1.7971004101534673e-06} because of the following error: Exception('num_classes must be defined for segmentation task').
    Traceback (most recent call last):
      File "/u/ltizzei/.pyenv/versions/3.12.8/envs/it/lib/python3.12/site-packages/optuna/study/_optimize.py", line 197, in _run_trial
        value_or_values = func(trial)
                          ^^^^^^^^^^^
      File "/u/ltizzei/Projects/Orgs/IBM/terratorch-iterate/benchmark/model_fitting.py", line 446, in fit_model_with_hparams
        return fit_model(
               ^^^^^^^^^^
      File "/u/ltizzei/Projects/Orgs/IBM/terratorch-iterate/benchmark/model_fitting.py", line 357, in fit_model
        lightning_task = lightning_task_class(**task.terratorch_task)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/u/ltizzei/.pyenv/versions/3.12.8/envs/it/lib/python3.12/site-packages/terratorch/tasks/segmentation_tasks.py", line 143, in __init__
        super().__init__(
      File "/u/ltizzei/.pyenv/versions/3.12.8/envs/it/lib/python3.12/site-packages/terratorch/tasks/base_task.py", line 38, in __init__
        super().__init__()
      File "/u/ltizzei/.pyenv/versions/3.12.8/envs/it/lib/python3.12/site-packages/torchgeo/trainers/base.py", line 42, in __init__
        self.configure_models()
      File "/u/ltizzei/.pyenv/versions/3.12.8/envs/it/lib/python3.12/site-packages/terratorch/tasks/base_task.py", line 51, in configure_models
        self.model: Model = self.model_factory.build_model(
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/u/ltizzei/.pyenv/versions/3.12.8/envs/it/lib/python3.12/site-packages/terratorch/models/prithvi_model_factory.py", line 96, in build_model
        return self._factory.build_model(task,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/u/ltizzei/.pyenv/versions/3.12.8/envs/it/lib/python3.12/site-packages/terratorch/models/encoder_decoder_factory.py", line 196, in build_model
        return _build_appropriate_model(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/u/ltizzei/.pyenv/versions/3.12.8/envs/it/lib/python3.12/site-packages/terratorch/models/encoder_decoder_factory.py", line 254, in _build_appropriate_model
        return PixelWiseModel(
               ^^^^^^^^^^^^^^^
      File "/u/ltizzei/.pyenv/versions/3.12.8/envs/it/lib/python3.12/site-packages/terratorch/models/pixel_wise_model.py", line 58, in __init__
        self._get_head(task, decoder.out_channels, head_kwargs) if not decoder_includes_head else nn.Identity()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/u/ltizzei/.pyenv/versions/3.12.8/envs/it/lib/python3.12/site-packages/terratorch/models/pixel_wise_model.py", line 154, in _get_head
        raise Exception(msg)
    Exception: num_classes must be defined for segmentation task
    [W 2025-08-06 15:44:32,197] Trial 0 failed with value None.
  3. leotizzei commented on Sep 25, 2025

    @leotizzei
    Contributor

    @paolofraccaro , I've copied two config files from terratorch, converted them using the script (this file and this file) and then run terratorch iterate. Both tests passed.

  4. paolofraccaro commented on Sep 26, 2025

    @paolofraccaro
    CollaboratorAuthor

    This is great! I would not call the script build_geobench_configs! Rather build iterate config. We could have a shortcut maybe terratorch iterate --build_iterate_config --config x.yaml?

  5. leotizzei commented on Sep 26, 2025

    @leotizzei
    Contributor

    Hi @paolofraccaro , that's a good idea! I'll change main.py module to allow users to run the script using terratorch iterate. Your previous script allows users to convert multiple terratorch's configs into one or more iterate's config. The last script that you shared with me does not allow that. My understanding is that it is still useful to allow users to convert multiple terratorch's configs. If so, then users would run:

     terratorch iterate --build_iterate_config --input <directory-that-contain-terratorch-configs> --ouput <directory-to-store-iterate-configs> --template <path-to-template>

    but it would also be possible to convert a single config file:

     terratorch iterate --build_iterate_config --input <terratorch-config-file> --ouput <iterate-config-file> --template <path-to-template>

    please let me know your thoughts on this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions