Skip to content

comet_ml.Artifact ¶

Artifact(
    name: str,
    artifact_type: Optional[str] = None,
    version: Optional[str] = None,
    aliases: Optional[Iterable[str]] = None,
    metadata: Any = None,
    version_tags: Optional[Iterable[str]] = None,
)

Comet Artifacts allow keeping track of assets beyond any particular experiment. You can keep track of Artifact versions, create many types of assets, manage them, and use them in any step in your ML pipelines---from training to production deployment.

Artifacts live in a Comet Project, are identified by their name and version string number.

Example how to log an artifact with an asset:

from comet_ml import Artifact, Experiment

experiment = Experiment()
artifact = Artifact("Artifact-Name", "Artifact-Type")
artifact.add("local-file")

experiment.log_artifact(artifact)
experiment.end()

Example how to get and download an artifact assets:

from comet_ml import Experiment

experiment = Experiment()
artifact = experiment.get_artifact("Artifact-Name", WORKSPACE, PROJECT_NAME)

artifact.download("/data/input")

The artifact is created on the frontend only when calling Experiment.log_artifact

Parameters:

  • name (str) –

    The artifact name. Exceeding 100 characters length will cause an exception.

  • artifact_type (str, default: None ) –

    The artifact-type, for example dataset.

  • version (str, default: None ) –

    The version number to create. If not provided, a new version number will be created automatically.

  • aliases (Iterable[str], default: None ) –

    Some aliases to attach to the future Artifact Version. The aliases list is converted into a set for de-duplication.

  • metadata (dict, default: None ) –

    Some additional data to attach to the future Artifact Version. Must be a JSON-encodable dict.

Attributes¶

assets property ¶

assets: List[ArtifactAsset]

The list of ArtifactAssets that have been logged with this Artifact.

download_local_path property ¶

download_local_path: Optional[str]

If the Artifact object was returned by LoggedArtifact.download, returns the root path where the assets have been downloaded. Else, returns None.

Functions¶

add ¶

add(
    local_path_or_data: Any,
    logical_path: Optional[str] = None,
    overwrite: bool = False,
    copy_to_tmp: bool = True,
    metadata: Optional[Dict[str, Any]] = None,
) -> None

Add a local asset to the current pending artifact object.

Parameters:

  • local_path_or_data (str | File - like) –

    Either a file/directory path of the files you want to log, or a file-like asset.

  • logical_path (str, default: None ) –

    A custom file name to be displayed. If not provided the filename from the local_path_or_data argument will be used.

  • overwrite (bool, default: False ) –

    If True will overwrite all existing assets with the same name.

  • copy_to_tmp (bool, default: True ) –

    If local_path_or_data is a file-like object, then this flag determines if the file is first copied to a temporary file before upload. If copy_to_tmp is False, then it is sent directly to the cloud.

  • metadata (dict, default: None ) –

    Some additional data to attach to the the audio asset. Must be a JSON-encodable dict.

add_remote ¶

add_remote(
    uri: str,
    logical_path: Optional[str] = None,
    overwrite: bool = False,
    asset_type: Optional[str] = None,
    metadata: Optional[Dict[str, Any]] = None,
    sync_mode: bool = True,
    max_synced_objects: int = 10000,
) -> None

Add a remote asset to the current pending artifact object. A Remote Asset is an asset but its content is not uploaded and stored on Comet. Rather a link for its location is stored so you can identify and distinguish between two experiment using different version of a dataset stored somewhere else.

Parameters:

  • uri (str) –

    The remote asset location, there is no imposed format and it could be a private link.

  • logical_path (str, default: None ) –

    The "name" of the remote asset, could be a dataset name, a model file name.

  • overwrite (bool, default: False ) –

    If True will overwrite all existing assets with the same name.

  • asset_type (str, default: None ) –

    Define the type of the asset - Deprecated.

  • metadata (dict, default: None ) –

    Some additional data to attach to the remote asset. Must be a JSON-encodable dict.

  • sync_mode (bool, default: True ) –

    If True and the URI begins with s3://, Comet attempts to list all objects in the given bucket and path. Each object will be logged as a separate remote asset. If object versioning is enabled on the S3 bucket, Comet also logs each object version to be able to download the exact version. If False, Comet just logs a single remote asset with the provided URI as the remote URI. Default is True.

  • max_synced_objects (int, default: 10000 ) –

    When sync_mode is True and the URI begins with s3://, set the maximum number of S3 objects to log. If there are more matching S3 objects than max_synced_objects, a warning will be displayed and the provided URI will be logged as a single remote asset.

Nov. 18, 2024