File size: 5,976 Bytes
3da7bcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

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