update()
Parameters:
instance_list
: A Python list with the instances for the file to update. Required for image type files.frame_packet_map
: A Python Dictionary with the instance_list per frame of a video. Required for video type images. To read more about this formate check: Understanding Diffgram's File Formatoverwrite
: Boolean value. If true, it will archive all the existing instances on the file and set only the instances seen on the new giveninstance_list
orframe_packet_map
Description
Updates an existing file with new instances, all the instances should follow the schema described in Understanding Diffgram's File Format .
Warning: Overwriting is a Destructive Action
When you set the
overwrite=True
flag on this method. All existing instances will be deleted, this means any human made labels made on the UI will not exist anymore and can cause unexpected data loss if used on the wrong file or at the wrong moment in the training pipeline. Please use with caution.
Examples
1. Uploading a Frame Packet Map For a Video
In the following example we show how to upload a sample frame_packet_map to a video:
from diffgram.core.core import Project
def build_frame_packet_map():
result = {}
for i in range(253):
result[i] = [
{
'type': 'box',
'name': 'hot dog',
'x_min': 100,
'y_min': 100,
'x_max': 200,
'y_max': 200,
'frame_number: i,
'number': 1 # The sequence number.
}
]
return result
project = Project(project_string_id = "test_project",
client_id = "client_id",
client_secret = "client_secret")
file = project.file.get_by_id(<your_video_file_id>)
f_packet_map = build_frame_packet_map()
# Update video without removing existing instances.
file.update(frame_packet_map=f_packet_map)
# Update video and remove all existing instances.
file.update(frame_packet_map=f_packet_map, overwrite=True)
https://github.com/diffgram/diffgram/blob/master/sdk/diffgram/file/test_existing_instances.py#L130
2 Updating Attributes of a File
Let's say you want to update an attribute from an existing instance on an existing file.
For a radio button the existing instance list might look something like this. For other attribute type formats see Uploading Attributes
{
"type": "box",
"id": 123,
"x_max": 180,
"x_min": 100,
"y_max": 230,
"y_min": 130,
'attribute_groups': {
display_name: "My selected option" # The display name of the selected attribute option
id: 2 #The ID of the selected attribute option
name: "My selected option" # The internal name of the selected attribute option.,
}
# ... rest of instance data
}
]
Note You can get the existing instance list by doing:
file=project.file.get_by_id(id=22, with_instances=True)
print(file.instance_list)
To Update it, simply copy the same instance_list
structure and change the dictionary inside the attribute_groups
section on the instance to the one which corresponds to the new selected option. To the new option ID. In this example, we would replace the display_name
, id
and name
option,
project = Project(project_string_id = "test_project",
client_id = "client_id",
client_secret = "client_secret")
file = project.file.get_by_id(<your_file_id>)
new_instance_list = [
{
"type": "box",
"id": 123,
"x_max": 180,
"x_min": 100,
"y_max": 230,
"y_min": 130,
'attribute_groups': {
display_name: "My new option" # The display name updated optuon
id: 3 #The ID of the updated option
name: "My new option" # The internal name of updated attribute option.,
}
# ... rest of instance data
}
]
file.update(instance_list=new_instance_list)
Updated about 2 years ago