You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Creating-Datasets/custom-metadata-automation-script.mdx
+47-3Lines changed: 47 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title:"Custom MetadataAutomation Script"
2
+
title:"Custom MetadataUpload Script"
3
3
description:"Example Python script for automating custom metadata uploads to Visual Layer from folders with individual metadata JSON files."
4
-
sidebarTitle:"Automation script"
4
+
sidebarTitle:"Custom metadata Upload"
5
5
---
6
6
7
7
<Cardtitle="What This Helps With"icon="code">
@@ -60,6 +60,12 @@ The automation script demonstrates the complete Visual Layer custom metadata API
60
60
- Automatically truncates strings to Visual Layer's 255-character limit
61
61
- Handles nested objects by serializing to JSON
62
62
63
+
<Note>
64
+
**Adding vs. Updating Metadata:**
65
+
-**Adding new fields:** In case custom metadata was already uploaded to a dataset, the script will add new fields.
66
+
-**Updating existing fields:** Currently updating existing metadata is not supported. Contact Visual Layer for assistance with updating existing metadata values
67
+
</Note>
68
+
63
69
##Prerequisites
64
70
65
71
Before using the script, ensure you have:
@@ -83,6 +89,34 @@ your-folder/
83
89
└── image3.jpg.metadata.json
84
90
```
85
91
92
+
<Tip>
93
+
The`.metadata.json` file naming convention can be customized in the script's`scan_folder()` function to match your specific metadata storage format and naming patterns.
94
+
</Tip>
95
+
96
+
###Alternative: Single JSON File
97
+
98
+
If your metadata is in a single JSON file instead of individual files per image:
99
+
100
+
**Example JSON format:**
101
+
```json
102
+
{
103
+
"image1.jpg": {
104
+
"confidence":0.95,
105
+
"category":"approved"
106
+
},
107
+
"image2.jpg": {
108
+
"confidence":0.87,
109
+
"category":"pending"
110
+
}
111
+
}
112
+
```
113
+
114
+
**To use this format:** Add the`load_single_json_metadata()` method to the`FolderMetadataProcessor` class and call it instead of`scan_folder()` +`load_metadata_files()` in the workflow.
115
+
116
+
<Cardtitle="View Single JSON Implementation"icon="code"href="/docs/code-blocks/custom-metadata-upload-script">
117
+
See the complete code example for handling single JSON files at the bottom of the page.
118
+
</Card>
119
+
86
120
###Metadata File Format
87
121
88
122
Each`.metadata.json` file should contain field-value pairs:
@@ -105,6 +139,16 @@ Each `.metadata.json` file should contain field-value pairs:
- Objects:`{"key": "value"}` (serialized to JSON string)
107
141
142
+
###Expected Result in Visual Layer
143
+
144
+
After running the script, your custom metadata fields will be visible in Visual Layer's interface for each image:
145
+
146
+
<Frame>
147
+
<imgsrc="/images/custom-metadata-example.png"alt="Custom metadata displayed in Visual Layer showing fields like name, float value, list of tags, condition, and date" />
148
+
</Frame>
149
+
150
+
These fields become searchable and filterable, enabling you to query and analyze your dataset based on your custom metadata.