kreshuklab / go-nuclear

Guides and code for 3D nuclear instance segmentation
MIT License
20 stars 3 forks source link

run-stardist model_dir KeyError #6

Open marcodallavecchia opened 1 day ago

marcodallavecchia commented 1 day ago

Running the train_and_infer.yml config file adapting the input and output paths, returns the following errors:

11/29/2024 03:17:14 PM INFO - Loading configs
Traceback (most recent call last):
  File "/nfs/scistore08/imagegrp/mdallave/.conda/envs/run-stardist/bin/predict-stardist", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/nfs/scistore08/imagegrp/mdallave/.conda/envs/run-stardist/lib/python3.11/site-packages/runstardist/predict.py", line 117, in main
    config_all = ConfigPred(**config)
                 ^^^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
  File "pydantic/main.py", line 1074, in pydantic.main.validate_model
  File "pydantic/fields.py", line 881, in pydantic.fields.ModelField.validate
  File "pydantic/fields.py", line 1098, in pydantic.fields.ModelField._validate_singleton
  File "pydantic/fields.py", line 1154, in pydantic.fields.ModelField._apply_validators
  File "pydantic/class_validators.py", line 337, in pydantic.class_validators._generic_validator_basic.lambda13
  File "pydantic/main.py", line 711, in pydantic.main.BaseModel.validate
  File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
  File "pydantic/main.py", line 1074, in pydantic.main.validate_model
  File "pydantic/fields.py", line 895, in pydantic.fields.ModelField.validate
  File "pydantic/fields.py", line 1154, in pydantic.fields.ModelField._apply_validators
  File "pydantic/class_validators.py", line 306, in pydantic.class_validators._generic_validator_cls.lambda5
  File "/nfs/scistore08/imagegrp/mdallave/.conda/envs/run-stardist/lib/python3.11/site-packages/runstardist/config.py", line 118, in model_name_is_valid
    if not (values['model_dir'] / v).is_dir():
            ~~~~~~^^^^^^^^^^^^^
KeyError: 'model_dir'

This is the content of the yaml file:

stardist:
  model_dir: Null
  model_name: generic_plant_nuclei_3D # `generic_plant_nuclei_3D` is the default builtin model
  model_type: StarDist3D
  model_config: # model configuration should stay identical for training and inference
    backbone: resnet
    n_rays: 96
    grid: [2, 4, 4]
    use_gpu: False
    n_channel_in: 1
    patch_size: [96, 96, 96] # multiple of 16 prefered
    train_batch_size: 8
    train_n_val_patches: 16
    steps_per_epoch: 400
    epochs: 1000

Replacing the Null for a path, fails to find the model:

11/29/2024 03:19:59 PM INFO - Loading configs
{}
Traceback (most recent call last):
  File "/nfs/scistore08/imagegrp/mdallave/.conda/envs/run-stardist/bin/predict-stardist", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/nfs/scistore08/imagegrp/mdallave/.conda/envs/run-stardist/lib/python3.11/site-packages/runstardist/predict.py", line 117, in main
    config_all = ConfigPred(**config)
                 ^^^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
  File "pydantic/main.py", line 1074, in pydantic.main.validate_model
  File "pydantic/fields.py", line 881, in pydantic.fields.ModelField.validate
  File "pydantic/fields.py", line 1098, in pydantic.fields.ModelField._validate_singleton
  File "pydantic/fields.py", line 1154, in pydantic.fields.ModelField._apply_validators
  File "pydantic/class_validators.py", line 337, in pydantic.class_validators._generic_validator_basic.lambda13
  File "pydantic/main.py", line 711, in pydantic.main.BaseModel.validate
  File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
  File "pydantic/main.py", line 1074, in pydantic.main.validate_model
  File "pydantic/fields.py", line 895, in pydantic.fields.ModelField.validate
  File "pydantic/fields.py", line 1154, in pydantic.fields.ModelField._apply_validators
  File "pydantic/class_validators.py", line 306, in pydantic.class_validators._generic_validator_cls.lambda5
  File "/nfs/scistore08/imagegrp/mdallave/.conda/envs/run-stardist/lib/python3.11/site-packages/runstardist/config.py", line 119, in model_name_is_valid
    raise NotADirectoryError(f"Model {v} does not exist.")
NotADirectoryError: Model generic_plant_nuclei_3D does not exist.
qin-yu commented 1 hour ago

Thank you @marcodallavecchia for reporting this! I'll have a look. (formatted the issue for readability)