torchtraining.callbacks.neptune module¶
Integrate torchtraining with neptune.ai experiment management tool.
Note
IMPORTANT: This module is experimental and may not be working correctly. Use at your own risk and report any issues you find.
Note
IMPORTANT: This module needs neptune-client Python package to be available.
You can install it with pip install -U torchtraining[neptune]
Usage is similar to torchtraining.callbacks.Tensorboard, except creating project
instead of torch.utils.tensorboard.SummaryWriter.
Example:
import torchtraining as tt
import torchtraining.callbacks.neptune as neptune
class TrainStep(tt.steps.Train):
def forward(self, module, sample):
# Dummy step
images, labels = sample
return images
project = neptune.project()
experiment = neptune.experiment(project)
step = TrainStep(criterion, device)
# Experiment is optional
# You have to split `tensor` as only single image can be logged
# Also you need to cast to `numpy`
step ** tt.OnSplittedTensor(tt.cast.Numpy() ** neptune.Image(experiment))
-
class
torchtraining.callbacks.neptune.Artifact(destination=None, experiment=None)[source]¶ Bases:
torchtraining.callbacks.neptune._NeptuneOperationSave an artifact (file) in experiment storage.
- Parameters
- Returns
Data without any modification
- Return type
data
-
class
torchtraining.callbacks.neptune.Image(log_name: str, image_name: str = None, description: str = None, timestamp=None, experiment=None)[source]¶ Bases:
torchtraining.callbacks.neptune._NeptuneOperationLog image data in Neptune.
Example:
import torchtraining as tt import torchtraining.callbacks.neptune as neptune class TrainStep(tt.steps.Train): def forward(self, module, sample): # Dummy step images, labels = sample # Images is of shape [batch, 1, 28, 28], say MNIST return images project = neptune.project() experiment = neptune.experiment(project) step = TrainStep(criterion, device) # Experiment is optional # You have to split `tensor` as only single image can be logged # Also you need to cast to `numpy` step ** tt.OnSplittedTensor(tt.cast.Numpy() ** neptune.Image(experiment))
- Parameters
log_name (str) – Name of log (group of images), e.g. “generated images”.
image_name (str, optional) – Name of this specific image received in
data. IfNoneconsecutive numbers will be used. Default:Nonedescription (str, optional) – Textual description of image. If
Noneno description. Default:Nonetimestamp (time, optional) – Timestamp to be associated with log entry. Must be Unix time. If None is passed, time.time() (Python 3.6 example) is invoked to obtain timestamp. Default
Noneexperiment (
neptune.experiments.Experiment, optional) –Instance of experiment to use. If
None, globalexperimentwill be used. Default:NoneReturns
------- –
data – Data without any modification
-
forward(data)[source]¶ - Parameters
data (PIL image | matplotlib.figure.Figure | str | np.array) –
Can be one of: *
PIL imagematplotlib.figure.FigureMatplotlib 3.1.1 docsstr- path to image file2-dimensional
numpy.array- interpreted as grayscale image3-dimensional
numpy.array- behavior depends on last dimensionif last dimension is 1 - interpreted as grayscale image
if last dimension is 3 - interpreted as RGB image
if last dimension is 4 - interpreted as RGBA image
You may need to
transposeand transform PyTorchtensorsto fit the above format.
-
class
torchtraining.callbacks.neptune.Reset(log_name: str, experiment=None)[source]¶ Bases:
torchtraining.callbacks.neptune._NeptuneOperationResets the log.
Removes all data from the log and enables it to be reused from scratch. See original documentation.
Example:
import torchtraining as tt import torchtraining.callbacks.neptune as neptune class TrainStep(tt.steps.Train): def forward(self, module, sample): ... # You returning text for some reason... return loss, text project = neptune.project() neptune.experiment(project) step = TrainStep(criterion, device) # Experiment is optional # You have to split `tensor` as only single image can be logged # Also you need to cast to `numpy` step ** tt.Select(text=1) ** neptune.Text())
- Parameters
log_name (str) – Name of log (group of images), e.g. “generated images”. If
logdoes not exist, errorChannelDoesNotExistwill be raised.- Returns
Anything which was passed into it.
- Return type
data
-
class
torchtraining.callbacks.neptune.Scalar(log_name: str, timestamp=None, experiment=None)[source]¶ Bases:
torchtraining.callbacks.neptune._NeptuneOperationLog scalar data in Neptune.
Calls
experiment.log_metricunder the hood. See original documentation.Example:
import torchtraining as tt import torchtraining.callbacks.neptune as neptune class TrainStep(tt.steps.Train): def forward(self, module, sample): # Dummy step # Calculate loss ... return loss project = neptune.project() experiment = neptune.experiment(project) step = TrainStep(criterion, device) # Experiment is optional # You have to split `tensor` as only single image can be logged # Also you need to cast to `numpy` step ** tt.cast.Item() ** neptune.Image(experiment))
- Parameters
log_name (str) – Name of log (group of images), e.g. “generated images”.
timestamp (time, optional) – Timestamp to be associated with log entry. Must be Unix time. If None is passed, time.time() (Python 3.6 example) is invoked to obtain timestamp. Default
Noneexperiment (
neptune.experiments.Experiment, optional) – Instance of experiment to use. IfNone, globalexperimentwill be used. Default:None
- Returns
Data without any modification
- Return type
data
-
class
torchtraining.callbacks.neptune.Text(log_name: str, timestamp=None, experiment=None)[source]¶ Bases:
torchtraining.callbacks.neptune._NeptuneOperationLog text data in Neptune.
Example:
import torchtraining as tt import torchtraining.callbacks.neptune as neptune class TrainStep(tt.steps.Train): def forward(self, module, sample): ... # You returning text for some reason... return loss, text project = neptune.project() neptune.experiment(project) step = TrainStep(criterion, device) # Experiment is optional # You have to split `tensor` as only single image can be logged # Also you need to cast to `numpy` step ** tt.Select(text=1) ** neptune.Text())
- Parameters
log_name (str) – Name of log (group of images), e.g. “generated images”.
timestamp (time, optional) – Timestamp to be associated with log entry. Must be Unix time. If None is passed, time.time() (Python 3.6 example) is invoked to obtain timestamp. Default
Noneexperiment (
neptune.experiments.Experiment, optional) – Instance of experiment to use. IfNone, globalexperimentwill be used. Default:None
- Returns
Data without any modification
- Return type
data
-
torchtraining.callbacks.neptune.experiment(self, project=None, name=None, description=None, params=None, properties=None, tags=None, upload_source_files=None, abort_callback=None, logger=None, upload_stdout=True, upload_stderr=True, send_hardware_metrics=True, run_monitoring_thread=True, handle_uncaught_exceptions=True, git_info=None, hostname=None, notebook_id=None, notebook_path=None)[source]¶ Create and start Neptune experiment.
Create experiment, set its status to running and append it to the top of the experiments view. All parameters are optional.
Extensive documentation (explained optional parameters) is located here
neptune.experiments.Experimentobject that is used to manage experiment and log data to it. See original documentation)ExperimentValidationError: When provided arguments are invalid.ExperimentLimitReached: When experiment limit in the project has been reached.
-
torchtraining.callbacks.neptune.project(project_qualified_name=None, api_token=None, proxies=None, backend=None)[source]¶ Initialize Neptune client library to work with specific project.
Authorize user, sets value of global variable project to Project object that can be used to create or list experiments, notebooks, etc.
Extensive documentation (explained optional parameters) is located here .
- Returns
Object that is used to create or list experiments, notebooks, etc.
- Return type
neptune.Project