###but get this error I think related to train_multilabel.py
valid_loader = DataLoader(
valid_dataset,
batch_size=config.valid.get('batch_size', config.train.batch_size),
num_workers=config.valid.get('num_workers', config.train.num_workers),
pin_memory=True,
shuffle=False
)
###here's the error
(sam3) samerkharboush@Samers-MBP SAR-MPS-OptunaNasFbnYoloTransformers % HYDRA_FULL_ERROR=1 python train_multilabel.py
DEBUG:git.cmd:Popen(['git', 'version'], cwd=/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers, stdin=None, shell=False, universal_newlines=False)
DEBUG:git.cmd:Popen(['git', 'version'], cwd=/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers, stdin=None, shell=False, universal_newlines=False)
DEBUG:hydra.core.utils:Setting JobRuntime:name=UNKNOWN_NAME
DEBUG:hydra.core.utils:Setting JobRuntime:name=train_multilabel
Error executing job with overrides: []
Traceback (most recent call last):
File "/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers/train_multilabel.py", line 499, in
main()
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/main.py", line 94, in decorated_main
_run_hydra(
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/utils.py", line 394, in _run_hydra
_run_app(
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/utils.py", line 457, in _run_app
run_and_report(
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/utils.py", line 223, in run_and_report
raise ex
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/utils.py", line 220, in run_and_report
return func()
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/utils.py", line 458, in
lambda: hydra.run(
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/_internal/hydra.py", line 132, in run
_ = ret.return_value
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/core/utils.py", line 260, in return_value
raise self._return_value
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/hydra/core/utils.py", line 186, in run_job
ret.return_value = task_function(task_cfg)
File "/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers/train_multilabel.py", line 495, in main
pipeline.train()
File "/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers/train_multilabel.py", line 395, in train
train_loader, valid_loader, _, dataset_callbacks = self.build_datasets(config)
File "/Users/samerkharboush/Downloads/SAR-MPS-OptunaNasFbnYoloTransformers/train_multilabel.py", line 95, in build_datasets
valid_image_size = config.valid.image_size if 'image_size' in config.valid else [2048, 2048]
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 359, in getattr
self._format_and_raise(key=key, value=None, cause=e)
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/base.py", line 231, in _format_and_raise
format_and_raise(
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/_utils.py", line 819, in format_and_raise
_raise(ex, cause)
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/_utils.py", line 797, in _raise
raise ex.with_traceback(sys.exc_info()[2]) # set env var OC_CAUSE=1 for full trace
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 351, in getattr
return self._get_impl(
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 442, in _get_impl
node = self._get_child(
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/basecontainer.py", line 73, in _get_child
child = self._get_node(
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 475, in _get_node
self._validate_get(key)
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/dictconfig.py", line 164, in _validate_get
self._format_and_raise(
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/base.py", line 231, in _format_and_raise
format_and_raise(
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/_utils.py", line 899, in format_and_raise
_raise(ex, cause)
File "/opt/anaconda3/envs/sam3/lib/python3.9/site-packages/omegaconf/_utils.py", line 797, in _raise
raise ex.with_traceback(sys.exc_info()[2]) # set env var OC_CAUSE=1 for full trace
omegaconf.errors.ConfigAttributeError: Key 'valid' is not in struct
full_key: valid
object_type=dict
(sam3) samerkharboush@Samers-MBP SAR-MPS-OptunaNasFbnYoloTransformers %
###I think in the train file method cause this error
this
def build_datasets(self, config: DictConfig) -> Tuple[DataLoader, DataLoader, Optional[DataLoader], List[Callback]]:
"""
Builds and returns DataLoaders for training and validation datasets.
"""
dataset_module = MultilabelCircleNetDataModule(config=config)
code
train_image_size = config.train.image_size if 'image_size' in config.train else [512, 512]
valid_image_size = config.valid.image_size if 'image_size' in config.valid else [2048, 2048]
train_df, valid_df, _, shore_root = dataset_module.train_val_split(
splitter=config.dataset.splitter,
fold=config.dataset.fold,
num_folds=config.dataset.num_folds,
)
The error you're encountering indicates that the configuration (config) lacks a valid section. Specifically, the line:
python
valid_image_size = config.valid.image_size if 'image_size' in config.valid else [2048, 2048]
is attempting to access config.valid.image_size, but the valid key doesn't exist in your current configuration. This results in the ConfigAttributeError.
Solution: Add a valid Section to Your Configuration
To resolve this error, you need to define a valid section in your multilabel_circle_net.yaml configuration file. This section should contain the necessary parameters for validation, such as image_size, batch_size, and num_workers.
Here’s how you can update your configuration:
Add the valid Section:
Insert a valid section at the same hierarchical level as the train section. Here's an example based on typical validation settings:
yaml
# ... (previous configuration)
# Training Configuration
train:
slug: default_training
epochs: 4
output_stride: 32
early_stopping:
enabled: true
patience: 2
mode: "min" # Options: 'min' for loss-based, 'max' for accuracy-based
metric: "loss" # The metric to monitor for early stopping
image_size: [512, 512] # Example training image size
batch_size: 16 # Example training batch size
num_workers: 4 # Example number of workers for training
# Validation Configuration
valid:
image_size: [2048, 2048] # Default validation image size
batch_size: 16 # Example validation batch size
num_workers: 4 # Example number of workers for validation
Explanation:
image_size: Defines the dimensions of the images used during validation.
batch_size: Specifies the number of samples per validation batch.
num_workers: Indicates the number of subprocesses to use for data loading during validation.
Ensure Consistency with Training Parameters:
Make sure that the parameters you add under the valid section align with how your training script expects them. For example, if your training script uses config.valid.batch_size, ensure that this key exists and is correctly set.
Optional: Use Defaults or Inherit Parameters:
If you want the validation parameters to inherit some values from the training configuration, you can use YAML references or default values. However, based on your current setup, explicitly defining the valid section is the most straightforward approach.
Updated Configuration Example
Here's how your multilabel_circle_net.yaml might look after adding the valid section:
yaml
Key Points to Ensure Correctness
Ensure All Required Keys Are Present:
Depending on your training script's requirements, you might need to add more keys under the valid section (e.g., data transformations specific to validation).
Consistency with Training:
If you have specific data augmentations or preprocessing steps for validation, make sure they're correctly defined and referenced.
Defaults and Fallbacks:
In your build_datasets method, you already have fallback values ([512, 512] for training and [2048, 2048] for validation) if image_size isn't defined. However, it's better to explicitly define these to avoid confusion.
Validate the Updated Configuration:
After updating the yaml file, you can print out the configuration in your script to verify that the valid section is correctly parsed.
python
import hydra
from omegaconf import DictConfig
@hydra.main(config_path="path_to_config", config_name="multilabel_circle_net")
def main(cfg: DictConfig):
print(cfg.pretty())
if __name__ == "__main__":
main()
Test the Configuration:
Run your training script again to ensure that the error has been resolved. If other related errors appear, they might indicate further missing or misconfigured parameters.
Final Steps
Update multilabel_circle_net.yaml with the valid section as shown above.
Save the Configuration and ensure there are no YAML syntax errors.
Run Your Training Script Again:
bash
HYDRA_FULL_ERROR=1 python train_multilabel.py
Monitor for Errors:
If the error persists or new errors arise, revisit the configuration to ensure all necessary parameters are correctly defined.
By explicitly defining the valid section in your configuration, you provide your training script with the necessary parameters to initialize the validation DataLoader, thereby resolving the ConfigAttributeError.