diff --git a/segment/tutorial.ipynb b/segment/tutorial.ipynb index f2aee9e26b33..0ece0f60e4d6 100644 --- a/segment/tutorial.ipynb +++ b/segment/tutorial.ipynb @@ -63,7 +63,7 @@ "source": [ "!git clone https://github.com/ultralytics/yolov5 # clone\n", "%cd yolov5\n", - "%pip install -qr requirements.txt # install\n", + "%pip install -qr requirements.txt comet_ml # install\n", "\n", "import torch\n", "import utils\n", diff --git a/train.py b/train.py index 216da6399028..c87cbb2d71d7 100644 --- a/train.py +++ b/train.py @@ -26,6 +26,11 @@ from datetime import datetime from pathlib import Path +try: + import comet_ml # must be imported before torch (if installed) +except ImportError: + comet_ml = None + import numpy as np import torch import torch.distributed as dist diff --git a/tutorial.ipynb b/tutorial.ipynb index be87068822af..42c6bc632aec 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -59,7 +59,7 @@ "source": [ "!git clone https://github.com/ultralytics/yolov5 # clone\n", "%cd yolov5\n", - "%pip install -qr requirements.txt # install\n", + "%pip install -qr requirements.txt comet_ml # install\n", "\n", "import torch\n", "import utils\n", diff --git a/utils/__init__.py b/utils/__init__.py index 6c10857df079..bccac42711e6 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -54,7 +54,7 @@ def notebook_init(verbose=True): import os import shutil - from utils.general import check_font, check_requirements, is_colab + from utils.general import check_font, is_colab from utils.torch_utils import select_device # imports check_font() diff --git a/utils/loggers/__init__.py b/utils/loggers/__init__.py index c7c283b728ac..ba7d2790e613 100644 --- a/utils/loggers/__init__.py +++ b/utils/loggers/__init__.py @@ -46,15 +46,15 @@ clearml = None try: - if RANK not in [0, -1]: - comet_ml = None - else: + if RANK in {0, -1}: import comet_ml assert hasattr(comet_ml, '__version__') # verify package import not local dir from utils.loggers.comet import CometLogger -except (ModuleNotFoundError, ImportError, AssertionError): + else: + comet_ml = None +except (ImportError, AssertionError): comet_ml = None @@ -88,10 +88,6 @@ def __init__(self, save_dir=None, weights=None, opt=None, hyp=None, logger=None, self.csv = True # always log to csv # Messages - if not clearml: - prefix = colorstr('ClearML: ') - s = f"{prefix}run 'pip install clearml' to automatically track, visualize and remotely train YOLOv5 🚀 in ClearML" - self.logger.info(s) if not comet_ml: prefix = colorstr('Comet: ') s = f"{prefix}run 'pip install comet_ml' to automatically track and visualize YOLOv5 🚀 runs in Comet" diff --git a/utils/loggers/comet/__init__.py b/utils/loggers/comet/__init__.py index d4599841c9fc..aac06b11c8c0 100644 --- a/utils/loggers/comet/__init__.py +++ b/utils/loggers/comet/__init__.py @@ -18,7 +18,7 @@ # Project Configuration config = comet_ml.config.get_config() COMET_PROJECT_NAME = config.get_string(os.getenv('COMET_PROJECT_NAME'), 'comet.project_name', default='yolov5') -except (ModuleNotFoundError, ImportError): +except ImportError: comet_ml = None COMET_PROJECT_NAME = None @@ -82,7 +82,7 @@ def __init__(self, opt, hyp, run_id=None, job_type='Training', **experiment_kwar self.comet_log_batch_interval = COMET_BATCH_LOGGING_INTERVAL # Dataset Artifact Settings - self.upload_dataset = self.opt.upload_dataset if self.opt.upload_dataset else COMET_UPLOAD_DATASET + self.upload_dataset = self.opt.upload_dataset or COMET_UPLOAD_DATASET self.resume = self.opt.resume # Default parameters to pass to Experiment objects @@ -93,6 +93,7 @@ def __init__(self, opt, hyp, run_id=None, job_type='Training', **experiment_kwar 'project_name': COMET_PROJECT_NAME,} self.default_experiment_kwargs.update(experiment_kwargs) self.experiment = self._get_experiment(self.comet_mode, run_id) + self.experiment.set_name(self.opt.name) self.data_dict = self.check_dataset(self.opt.data) self.class_names = self.data_dict['names']