lightly
lightly copied to clipboard
Improve documentation on creating custom metadata
Description
There is currently no documentation on creating custom metadata in the coco format easily. Creating it by hand is not easy, as you need to take care of the image_ids. https://docs.lightly.ai/getting_started/platform.html#custom-metadata
Thus it would be good to show how to create a custom metadata file for more common formats, e.g. from a pandas dataframe.
Furthermore, the utility function save_custom_metadata() should be documented.
https://github.com/lightly-ai/lightly/blob/fb2fac9f8c2f211fa7b162ece530653f6b19d5f1/lightly/utils/io.py#L234
Example code
The script is fully working
import numpy as np
import pandas as pd
from lightly.utils import save_custom_metadata
df = pd.DataFrame({
"filename_A": [0, 3],
"filename_B": [2, 3],
"filename_C": [0, 7],
})
OUTPUT_FILE = "custom_metadata.json"
# create a list of pairs of (filename, metadata)
custom_metadata = []
for filename, data in df.items():
metadata = {
'lat': float(data[0]),
'long': float(data[1]),
'dist': float(np.sqrt(data[1] * data[1] + data[0] * data[0]))
}
custom_metadata.append((filename, metadata))
# save custom metadata in the correct json format
save_custom_metadata(OUTPUT_FILE, custom_metadata)