Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

40 lignes
1.7KB

  1. import argparse
  2. from pathlib import Path
  3. import yaml
  4. from wandb_utils import WandbLogger
  5. from utils.datasets import LoadImagesAndLabels
  6. WANDB_ARTIFACT_PREFIX = 'wandb-artifact://'
  7. def create_dataset_artifact(opt):
  8. with open(opt.data) as f:
  9. data = yaml.load(f, Loader=yaml.SafeLoader) # data dict
  10. logger = WandbLogger(opt, '', None, data, job_type='create_dataset')
  11. nc, names = (1, ['item']) if opt.single_cls else (int(data['nc']), data['names'])
  12. names = {k: v for k, v in enumerate(names)} # to index dictionary
  13. logger.log_dataset_artifact(LoadImagesAndLabels(data['train']), names, name='train') # trainset
  14. logger.log_dataset_artifact(LoadImagesAndLabels(data['val']), names, name='val') # valset
  15. # Update data.yaml with artifact links
  16. data['train'] = WANDB_ARTIFACT_PREFIX + str(Path(opt.project) / 'train')
  17. data['val'] = WANDB_ARTIFACT_PREFIX + str(Path(opt.project) / 'val')
  18. path = opt.data if opt.overwrite_config else opt.data.replace('.', '_wandb.') # updated data.yaml path
  19. data.pop('download', None) # download via artifact instead of predefined field 'download:'
  20. with open(path, 'w') as f:
  21. yaml.dump(data, f)
  22. print("New Config file => ", path)
  23. if __name__ == '__main__':
  24. parser = argparse.ArgumentParser()
  25. parser.add_argument('--data', type=str, default='data/coco128.yaml', help='data.yaml path')
  26. parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset')
  27. parser.add_argument('--project', type=str, default='YOLOv5', help='name of W&B Project')
  28. parser.add_argument('--overwrite_config', action='store_true', help='overwrite data.yaml')
  29. opt = parser.parse_args()
  30. create_dataset_artifact(opt)