newron.log_artifact()
newron.log_artifact(local_path: str, artifact_path: Optional[str] = None) → None
Log a local file or directory as an artifact of the currently active run. If no run is active, this method will create a new active run.
Parameters
- local_path – Denotes the path to the file to write.
- artifact_path – If provided, the directory in artifact_uri to write to.
Example
import newron
# Create a features.txt artifact file
features = "rooms, zipcode, median_price, school_rating, transport"
with open("features.txt", 'w') as f:
f.write(features)
# With artifact_path=None write features.txt under
# root artifact_uri/artifacts directory
newron.log_artifact("features.txt")
newron.log_artifacts()
newron.log_artifacts(local_dir: str, artifact_path: Optional[str] = None) → None
Log all the contents of a local directory as artifacts of the run. If no run is active, this method will create a new active run.
Parameters -
- local_dir - Denotes the path to the directory of files to write.
- artifact_path - If provided, it denotes the directory in artifact_uri to write to
Example
import os
import json
import newron
# Create some files to preserve as artifacts
features = "rooms, zipcode, median_price, school_rating, transport"
data = {"state": "TX", "Available": 25, "Type": "Detached"}
# Create couple of artifact files under the directory "data"
os.makedirs("data", exist_ok=True)
with open("data/data.json", 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2)
with open("data/features.txt", 'w') as f:
f.write(features)
# Write all files in "data" to root artifact_uri/states
newron.log_artifacts("data", artifact_path="states")
newron.log_image()
nweron.log_image(image: Union[numpy.ndarray, PIL.Image.Image], artifact_file: str) → None
Used to log image as an artifact. numpy.ndarray and PIL.Image.Image are the supported image object types.
Parameters
- image - Image to log
- artifact_file - The run-relative artifact file path in posixpath format to which the image is saved (e.g. “dir/image.png”).
Example
import newron
import numpy as np
image = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8)
newron.log_image(image, "image.png")
newron.log_text()
newron.log_text(text: str, artifact_file: str) → None
Used to log text as an artifact
Parameters
- text - String containing text to log
- artifact_file - The run-relative artifact file path in posixpath format to which the text is saved (e.g. “dir/file.txt”)
Example
import newron
with newron.start_run():
# Log text to a file under the run's root artifact directory
newron.log_text("text1", "file1.txt")
# Log text in a subdirectory of the run's root artifact directory
newron.log_text("text2", "dir/file2.txt")
# Log HTML text
newron.log_text("<h1>header</h1>", "index.html")