def __init__(self, api_key: Optional[str] = None, save_dir: Optional[str] = None, workspace: Optional[str] = None, project_name: Optional[str] = None, rest_api_key: Optional[str] = None, experiment_name: Optional[str] = None, experiment_key: Optional[str] = None, **kwargs): if not _COMET_AVAILABLE: raise ImportError( 'You want to use `comet_ml` logger which is not installed yet,' ' install it with `pip install comet-ml`.') super().__init__() self._experiment = None self._save_dir = save_dir # Determine online or offline mode based on which arguments were passed to CometLogger if api_key is not None: self.mode = "online" self.api_key = api_key elif save_dir is not None: self.mode = "offline" self._save_dir = save_dir else: # If neither api_key nor save_dir are passed as arguments, raise an exception raise MisconfigurationException( "CometLogger requires either api_key or save_dir during initialization." ) log.info(f"CometLogger will be initialized in {self.mode} mode") self.workspace = workspace self.project_name = project_name self.experiment_key = experiment_key self._kwargs = kwargs if rest_api_key is not None: # Comet.ml rest API, used to determine version number self.rest_api_key = rest_api_key self.comet_api = API(self.rest_api_key) else: self.rest_api_key = None self.comet_api = None if experiment_name: try: self.name = experiment_name except TypeError: log.exception( "Failed to set experiment name for comet.ml logger") self._kwargs = kwargs
def suggestion(self, skip_begin: int = 10, skip_end: int = 1): """ This will propose a suggestion for choice of initial learning rate as the point with the steepest negative gradient. Returns: lr: suggested initial learning rate to use skip_begin: how many samples to skip in the beginning. Prevent too naive estimates skip_end: how many samples to skip in the end. Prevent too optimistic estimates """ try: loss = self.results["loss"][skip_begin:-skip_end] min_grad = (np.gradient(np.array(loss))).argmin() self._optimal_idx = min_grad + skip_begin return self.results["lr"][self._optimal_idx] except Exception: log.exception('Failed to compute suggesting for `lr`. There might not be enough points.') self._optimal_idx = None
def __init__(self, api_key: Optional[str] = None, save_dir: Optional[str] = None, workspace: Optional[str] = None, project_name: Optional[str] = None, rest_api_key: Optional[str] = None, experiment_name: Optional[str] = None, experiment_key: Optional[str] = None, **kwargs): r""" Requires either an API Key (online mode) or a local directory path (offline mode) .. code-block:: python # ONLINE MODE from pytorch_lightning.loggers import CometLogger # arguments made to CometLogger are passed on to the comet_ml.Experiment class comet_logger = CometLogger( api_key=os.environ["COMET_API_KEY"], workspace=os.environ["COMET_WORKSPACE"], # Optional project_name="default_project", # Optional rest_api_key=os.environ["COMET_REST_API_KEY"], # Optional experiment_name="default" # Optional ) trainer = Trainer(logger=comet_logger) .. code-block:: python # OFFLINE MODE from pytorch_lightning.loggers import CometLogger # arguments made to CometLogger are passed on to the comet_ml.Experiment class comet_logger = CometLogger( save_dir=".", workspace=os.environ["COMET_WORKSPACE"], # Optional project_name="default_project", # Optional rest_api_key=os.environ["COMET_REST_API_KEY"], # Optional experiment_name="default" # Optional ) trainer = Trainer(logger=comet_logger) Args: api_key (str): Required in online mode. API key, found on Comet.ml save_dir (str): Required in offline mode. The path for the directory to save local comet logs workspace (str): Optional. Name of workspace for this user project_name (str): Optional. Send your experiment to a specific project. Otherwise will be sent to Uncategorized Experiments. If project name does not already exists Comet.ml will create a new project. rest_api_key (str): Optional. Rest API key found in Comet.ml settings. This is used to determine version number experiment_name (str): Optional. String representing the name for this particular experiment on Comet.ml. experiment_key (str): Optional. If set, restores from existing experiment. """ super().__init__() self._experiment = None # Determine online or offline mode based on which arguments were passed to CometLogger if api_key is not None: self.mode = "online" self.api_key = api_key elif save_dir is not None: self.mode = "offline" self.save_dir = save_dir else: # If neither api_key nor save_dir are passed as arguments, raise an exception raise MisconfigurationException("CometLogger requires either api_key or save_dir during initialization.") log.info(f"CometLogger will be initialized in {self.mode} mode") self.workspace = workspace self.project_name = project_name self.experiment_key = experiment_key self._kwargs = kwargs if rest_api_key is not None: # Comet.ml rest API, used to determine version number self.rest_api_key = rest_api_key self.comet_api = API(self.rest_api_key) else: self.rest_api_key = None self.comet_api = None if experiment_name: try: self.name = experiment_name except TypeError as e: log.exception("Failed to set experiment name for comet.ml logger") self._kwargs = kwargs