MMS-VPR / dataset_script.py
Yiwei-Ou's picture
Upload dataset_script.py
3da7bcd verified
import os
import pandas as pd
from pathlib import Path
import datasets
_CITATION = """
@inproceedings{your_neurips_submission,
title={Multimodal Street-level Place Recognition Dataset},
author={Ou, Yiwei},
year={2025},
booktitle={NeurIPS Datasets and Benchmarks Track}
}
"""
_DESCRIPTION = """
Multimodal Street-level Place Recognition Dataset (Resized version).
This version loads images, videos, and associated annotations for place recognition tasks,
including GPS, camera metadata, and temporal information.
"""
_HOMEPAGE = "https://huggingface.co/datasets/Yiwei-Ou/Multimodal_Street-level_Place_Recognition_Dataset"
_LICENSE = "cc-by-4.0"
class MultimodalPlaceRecognition(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({
"image_path": datasets.Value("string"),
"video_path": datasets.Value("string"),
"location_code": datasets.Value("string"),
"spatial_type": datasets.Value("string"),
"index": datasets.Value("int32"),
"shop_names": datasets.Value("string"),
"sign_text": datasets.Value("string"),
"image_metadata": datasets.Value("string"),
"video_metadata": datasets.Value("string"),
}),
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
archive_path = dl_manager.download_and_extract(
"https://huggingface.co/datasets/Yiwei-Ou/Multimodal_Street-level_Place_Recognition_Dataset/resolve/main/Annotated_Resized.tar.gz"
)
base_dir = os.path.join(archive_path, "03 Annotated_Resized", "Dataset_Full")
image_dir = os.path.join(base_dir, "Images")
video_dir = os.path.join(base_dir, "Videos")
text_dir = os.path.join(base_dir, "Texts")
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"image_dir": image_dir,
"video_dir": video_dir,
"annotations_path": os.path.join(text_dir, "Annotations.xlsx"),
"image_meta_path": os.path.join(text_dir, "Media_Metadata-Images.xlsx"),
"video_meta_path": os.path.join(text_dir, "Media_Metadata-Videos.xlsx"),
},
)
]
def _generate_examples(self, image_dir, video_dir, annotations_path, image_meta_path, video_meta_path):
id_ = 0
annotations_df = pd.read_excel(annotations_path, engine="openpyxl")
annotations_dict = {
str(row["Code"]).strip(): {
"spatial_type": str(row["Type"]).strip(),
"index": int(row["Index"]),
"shop_names": str(row["List of Store Names and Signs"]) if not pd.isna(row["List of Store Names and Signs"]) else "",
"sign_text": "", # Not explicitly available
}
for _, row in annotations_df.iterrows()
}
image_meta_df = pd.read_excel(image_meta_path, engine="openpyxl")
image_meta_dict = {
str(row["Filename"]).strip(): row.drop("Filename").dropna().to_dict()
for _, row in image_meta_df.iterrows()
}
video_meta_df = pd.read_excel(video_meta_path, engine="openpyxl")
video_meta_dict = {
str(row["Filename"]).strip(): row.drop("Filename").dropna().to_dict()
for _, row in video_meta_df.iterrows()
}
for spatial_type in os.listdir(image_dir):
spatial_path = os.path.join(image_dir, spatial_type)
if not os.path.isdir(spatial_path):
continue
for location_code in os.listdir(spatial_path):
loc_img_path = os.path.join(spatial_path, location_code)
if not os.path.isdir(loc_img_path):
continue
loc_vid_path = os.path.join(video_dir, spatial_type, location_code) if os.path.exists(os.path.join(video_dir, spatial_type, location_code)) else None
vid_files = set(os.listdir(loc_vid_path)) if loc_vid_path else set()
for file_name in os.listdir(loc_img_path):
if file_name.lower().endswith((".jpg", ".jpeg", ".png")):
base_name = os.path.splitext(file_name)[0]
video_match = [v for v in vid_files if v.startswith(base_name) and v.endswith(".mp4")]
video_file = video_match[0] if video_match else ""
video_path = os.path.join(loc_vid_path, video_file) if video_file else ""
meta = annotations_dict.get(location_code, {
"spatial_type": spatial_type,
"index": -1,
"shop_names": "",
"sign_text": "",
})
img_meta = image_meta_dict.get(file_name, {})
vid_meta = video_meta_dict.get(video_file, {}) if video_file else {}
yield id_, {
"image_path": os.path.join(loc_img_path, file_name),
"video_path": video_path,
"location_code": location_code,
"spatial_type": meta["spatial_type"],
"index": meta["index"],
"shop_names": meta["shop_names"],
"sign_text": meta["sign_text"],
"image_metadata": str(img_meta),
"video_metadata": str(vid_meta),
}
id_ += 1