rct_dataset / create_json.py
frutiemax's picture
Add helper scripts
fcbbb8b
raw
history blame
905 Bytes
import os
import pandas
from pathlib import Path
import string
import shutil
# read all the folders in data/train
data_folder = Path("./data/train")
folders = os.listdir(data_folder)
entries = []
image_index = 0
for folder in folders:
images_path = data_folder.joinpath(folder)
images = os.listdir(images_path)
view = 0
for image in images:
object_description = folder.replace('_', ' ')
entry = {'file_name' : image, 'object_type' : 'small_scenery', 'object_description' : object_description, 'view': view, 'color1' : 'none', 'color2' : 'none', 'color3' : 'none'}
entries.append(entry)
view = view + 1
#put the entries into the metadata.csv
dataframe = pandas.DataFrame(entries)
# dont overwrite the old metadata.csv
if os.path.exists('metadata.csv'):
shutil.copyfile('metadata.csv', 'metadata_backup.csv')
dataframe.to_csv('metadata.csv')