Model slices operate much like Catalog slices, both essentially functioning as saved searches that help filter large datasets into more manageable units. While Catalog slices function support Catalog, Model slices work within model runs. Model slices let you filter model run data rows into manageable units.Here, we show how to use the SDK to:
To interact with model slices, you must create a model experiment with a model run and then create a model slice through the platform. The steps below go over this process. See Slices Slicesfor more information
In this step, you will need to create a dataset to attach data rows to our model run.
Copy
Ask AI
# create a sample dataset to send to your modelglobal_key = str(uuid.uuid4())test_img_url = {"row_data":"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg","global_key":global_key}dataset = client.create_dataset(name="foundry-demo-dataset")task = dataset.create_data_rows([test_img_url])task.wait_till_done()print(f"Errors: {task.errors}")print(f"Failed data rows: {task.failed_data_rows}")# Create a model configurationmodel_run_name = "Model Slice Demo"example_config = {"learning_rate": 0.001,"batch_size": 32,}# Create a model runmodel_run = model.create_model_run(name=model_run_name, config=example_config)# Send the data rows to your modelmodel_run.upsert_data_rows(global_keys=[global_key])
From Model, select Experiment and select your model experiment.
2
A filter must be active to create a slice. From the Search menu, select Data row and then set the Condition menu to is not one of.
3
Set Search for an id to test and then press Enter to activate the filter. You can add additional filter conditions as needed.
Example of final view after executing step 2 -3
4
Select Save slice, name your slice, and then select Save. When you do this, the Slice menu displays the name of your slice and the number of matching data rows.
Data row identifiers are objects that contain both data row IDs and global keys.
Copy
Ask AI
data_row_identifiers = model_slice.get_data_row_identifiers(model_run.uid)drids = [dr for dr in data_row_identifiers]# get both global keys and data row ids# and utilize the hash method to combine both global keys and data row ids into a dictionaryfor dr in drids:print(f"Data row: {dr.id}, Global Key: {dr.global_key}, dr_gk: {dr.to_hash()}")
# name (str)model_slice.name# description (str)model_slice.description# updated at (datetime)model_slice.updated_at# created at (datetime)model_slice.created_at# filter (list[dict])model_slice.filter