Re-Enable Import Errors (#1938)

* update logger imports

* pep8 fixes

* pep8
This commit is contained in:
Justus Schock
2020-05-25 07:31:35 -04:00
committed by GitHub
parent caa9c6760b
commit 6456247287
6 changed files with 49 additions and 10 deletions
+12 -2
View File
@@ -16,9 +16,16 @@ try:
except ImportError: # pragma: no-cover
# For more information, see: https://www.comet.ml/docs/python-sdk/releases/#release-300
from comet_ml.papi import API # pragma: no-cover
_COMET_AVAILABLE = True
except ImportError: # pragma: no-cover
raise ImportError('You want to use `comet_ml` logger which is not installed yet,' # pragma: no-cover
' install it with `pip install comet-ml`.')
CometExperiment = None
CometExistingExperiment = None
CometOfflineExperiment = None
CometBaseExperiment = None
API = None
_COMET_AVAILABLE = False
import torch
from torch import is_tensor
@@ -93,6 +100,9 @@ class CometLogger(LightningLoggerBase):
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
+9 -2
View File
@@ -10,9 +10,11 @@ from typing import Optional, Dict, Any, Union
try:
import mlflow
from mlflow.tracking import MlflowClient
_MLFLOW_AVAILABLE = True
except ImportError: # pragma: no-cover
raise ImportError('You want to use `mlflow` logger which is not installed yet,' # pragma: no-cover
' install it with `pip install mlflow`.')
mlflow = None
MlflowClient = None
_MLFLOW_AVAILABLE = False
from pytorch_lightning import _logger as log
from pytorch_lightning.loggers.base import LightningLoggerBase
@@ -54,11 +56,16 @@ class MLFlowLogger(LightningLoggerBase):
tags: A dictionary tags for the experiment.
"""
def __init__(self,
experiment_name: str = 'default',
tracking_uri: Optional[str] = None,
tags: Optional[Dict[str, Any]] = None,
save_dir: Optional[str] = None):
if not _MLFLOW_AVAILABLE:
raise ImportError('You want to use `mlflow` logger which is not installed yet,'
' install it with `pip install mlflow`.')
super().__init__()
if not tracking_uri and save_dir:
tracking_uri = f'file:{os.sep * 2}{save_dir}'
+7 -2
View File
@@ -10,9 +10,11 @@ from PIL.Image import Image
try:
import neptune
from neptune.experiments import Experiment
_NEPTUNE_AVAILABLE = True
except ImportError: # pragma: no-cover
raise ImportError('You want to use `neptune` logger which is not installed yet,' # pragma: no-cover
' install it with `pip install neptune-client`.')
neptune = None
Experiment = None
_NEPTUNE_AVAILABLE = False
import torch
from torch import is_tensor
@@ -179,6 +181,9 @@ class NeptuneLogger(LightningLoggerBase):
properties: Optional[Dict[str, Any]] = None,
tags: Optional[List[str]] = None,
**kwargs):
if not _NEPTUNE_AVAILABLE:
raise ImportError('You want to use `neptune` logger which is not installed yet,'
' install it with `pip install neptune-client`.')
super().__init__()
self.api_key = api_key
self.project_name = project_name
+7 -2
View File
@@ -7,9 +7,10 @@ from typing import Optional, Dict, Any, Union
try:
from test_tube import Experiment
_TEST_TUBE_AVAILABLE = True
except ImportError: # pragma: no-cover
raise ImportError('You want to use `test_tube` logger which is not installed yet,' # pragma: no-cover
' install it with `pip install test-tube`.')
Experiment = None
_TEST_TUBE_AVAILABLE = False
from pytorch_lightning.loggers.base import LightningLoggerBase
from pytorch_lightning.utilities.distributed import rank_zero_only
@@ -62,6 +63,10 @@ class TestTubeLogger(LightningLoggerBase):
debug: bool = False,
version: Optional[int] = None,
create_git_tag: bool = False):
if not _TEST_TUBE_AVAILABLE:
raise ImportError('You want to use `test_tube` logger which is not installed yet,'
' install it with `pip install test-tube`.')
super().__init__()
self.save_dir = save_dir
self._name = name
+7
View File
@@ -14,7 +14,11 @@ from PIL.Image import Image
try:
import trains
from trains import Task
_TRAINS_AVAILABLE = True
except ImportError: # pragma: no-cover
trains = None
Task = None
_TRAINS_AVAILABLE = False
raise ImportError('You want to use `TRAINS` logger which is not installed yet,' # pragma: no-cover
' install it with `pip install trains`.')
@@ -91,6 +95,9 @@ class TrainsLogger(LightningLoggerBase):
auto_connect_frameworks: bool = True,
auto_resource_monitoring: bool = True
) -> None:
if not _TRAINS_AVAILABLE:
raise ImportError('You want to use `test_tube` logger which is not installed yet,'
' install it with `pip install test-tube`.')
super().__init__()
if self.bypass_mode():
self._trains = None
+7 -2
View File
@@ -11,9 +11,11 @@ import torch.nn as nn
try:
import wandb
from wandb.wandb_run import Run
_WANDB_AVAILABLE = True
except ImportError: # pragma: no-cover
raise ImportError('You want to use `wandb` logger which is not installed yet,' # pragma: no-cover
' install it with `pip install wandb`.')
wandb = None
Run = None
_WANDB_AVAILABLE = False
from pytorch_lightning.loggers.base import LightningLoggerBase
from pytorch_lightning.utilities import rank_zero_only
@@ -67,6 +69,9 @@ class WandbLogger(LightningLoggerBase):
experiment=None,
entity=None,
group: Optional[str] = None):
if not _WANDB_AVAILABLE:
raise ImportError('You want to use `wandb` logger which is not installed yet,' # pragma: no-cover
' install it with `pip install wandb`.')
super().__init__()
self._name = name
self._save_dir = save_dir