Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In order to add a property to the execution object in the MLMD MetadataStore using TensorFlow, you can follow these steps:

  1. Import the necessary dependencies, including tensorflow, mlmetadata, and the relevant metadatastore and metadata_proto modules.

  2. Initialize a metadata_store object by passing in the configuration details for your MLMD instance.

  3. Create an execution object using the metadatastore object's newexecution() method. You'll need to provide the appropriate context (e.g. a type and name for the execution) and any other relevant information (e.g. start time or properties).

  4. Retrieve the execution's metadata using the metadatastore object's getexecutionbyid() method. You'll need to pass in the execution's ID (which is returned when you create the execution object).

  5. Add the new property to the execution's metadata object using the metadata_proto module's Property() method. This method takes the name and value of the property as arguments.

  6. Add the property to the execution's metadata using the metadatastore object's putexecution() method. You'll need to pass in the updated metadata object, as well as the execution's ID.

  7. Close the connection to the metadata store by calling the metadata_store object's close() method.

Here's some sample code that demonstrates this process:

import tensorflow as tf
from ml_metadata import metadata_store, metadata_proto

# Initialize metadata store
metadata_config = metadata_store.MetadataStoreClientConfig(...)
store = metadata_store.MetadataStore(metadata_config)

# Create execution object
execution_context = metadata_proto.ExecutionContext(
    type="model_training",
    name="MyModelTraining",
    properties={"model_type": "convnet", "dataset": "cifar10"}
)
execution_id = store.new_execution(execution_context)

# Add property to execution
execution = store.get_execution_by_id(execution_id)
execution.properties["num_epochs"] = metadata_proto.Value(int_value=100)
store.put_execution(execution, execution_id)

# Close metadata store
store.close()