Trains Python Client Reference Overview

Automagical Trains captures a crucial set of experiment information.

This Trains Python client reference tells you how to extend further control over experimentation.

Task module

Reference page: Task (Experiment) Class

Module in the trains repository:

Using Trains, all Python experiment scripts import the Task class and initialize a Task object. This connects all the parts of the experiment and allows Trains automagically capture information.

The Task class contains much more. For example, the following methods support managing all the parts of experiments and integrating them with Trains for tracking, storage, coding, analysis, comparison, and experiment management:

  • connect() - Connect the parts of an experiment to the experiment in Trains, including hyperparameter dictionaries, input and output models, configuration dictionaries, and class enumeration labels.
  • get_logger() - Create a logger object which you can use for explicit reporting.
  • get_task() - Get a reference to any experiment in Trains by Task Id, or task and project name.
  • register_artifact() - Store an artifact which is dynamically synchronized with Trains.
  • get_registered_artifacts() - After you register an artifact, retrieve a reference to it, manipulate the artifact in your code, and the changes are updated in Trains.
  • upload_artifact() - Upload static (one-time) artifacts (which do not synchronize with Trains).
  • get_model_config_dict() - Get the configuration as a dictionary and then easily work with it in your code.
  • set_model_config() - Set the model configuration before creating an output model so that the output model inherits the configuration properties.
  • set_model_label_enumeration() - Similar to set_model_config(), but for class label enumeration.
  • clone() - Create an editable copy of an experiment. For example, clone an experiment for hyperparameter tuning or multiple times for autoML.
  • enqueue() - Add an experiment to a queue. Similar to dequeue() above, enqueue() allows you to develop scripts which can automate your experimentation.
  • dequeue() - Remove an enqueued experiment from a queue.
  • reset() - Delete a Completed, Aborted, or Failed status experiment's output data and make it editable with status Draft.

To learn how to use some of these important Task class methods, see our Explicit Reporting, Tuning Experiments, and AutoML tutorials.

Model module

Reference page: Model Class

Module in the trains repository:

Use the Model module's InputModel and OutputModel classes and methods to augment control of input models and output using methods such as:

  • InputModel.import_model() - Import a pre-trained model for your experiment.
  • InputModel.connect() - Connect the current model the Task (experiment).
  • InputModel.config_dict() - Get the input model's configuration as a dictionary.
  • InputModel.get_weights() - Download the base model.
  • OutputModel.connect() - Connect the output model to the Task (experiment).
  • OutputModel.set_upload_destination() - Specify a destination for uploading debug images.

Logger module

Reference page: Logger Class

Module in the trains repository:

Use the Logger class and methods to extend Trains automagical capturing of stdout and stderr with Trains' own explicit reporting for scalar metrics, any plot data in a variety of chart types, text messages, errors, warnings, debug messages, and uploading debug images, as well as other methods.

  • Logger.current_logger()
  • Logger.report_text()
  • Logger.report_scalar()
  • Logger.get_weights()
  • Logger.connect()
  • Logger.set_upload_destination()

To learn how to use explicit reporting, see our Explicit Reporting tutorials.