--- license: cc-by-4.0 --- # MapPool - Bubbling up an extremely large corpus of maps for AI (early access version) This repository contains URLs, textual descriptions, embeddings of 75 million potential maps. It has been derived from the [CommonPool dataset](https://huggingface.co/datasets/mlfoundations/datacomp_xlarge) from [DataComp](https://www.datacomp.ai/). The MapPool dataset may help to train resource-intensive architectures like Transformers or Diffusion Models in order to establish vision and language foundation models specialized on maps. ## How is the data structured? | Key | Meaning |----------------------------------|---------- | uid | Unique identifier | url | Link to the image | text | Textual description of the image | original_width / original_height | Dimensions of the image | sha256 | Hash of the image (to verify if the image is the same as the one in the URL) | l14_img | Embedding of the image (768 dimensions) | l14_txt | Embedding of the textual description (768 dimensions) | clip_l14_similarity_score | Similarity between the image and text (higher values indicate higher similarity) ## How can this repository be downloaded? Simply use Git (or TortoiseGit): ``` git clone https://huggingface.co/datasets/sraimund/MapPool/ ``` Alternatively use the HuggingFace API: ```python import json import os from huggingface_hub import hf_hub_download download_folder = "" repo_id = "sraimund/MapPool" # this file is given at the root of this repository with open("file_list.json") as f: file_list = json.load(f) for part, files in file_list.items(): for file in files: file_path = f"{download_folder}/{part}/{file}.parquet" if os.path.exists(file_path): continue hf_hub_download(repo_type="dataset", repo_id=repo_id, filename=f"{part}/{file}.parquet", local_dir=download_folder, token=read_token) ``` About 225 GB of space are required. The amount doubles when using Git since the files are duplicated in the .git folder. ## How can the parquet files be read? You can read parquet files with [pandas](https://pandas.pydata.org/): ```python import pandas as pd df = pd.read_parquet(".parquet") ``` The pyarrow or fastparquet library is required additionally. ## How can the map images be downloaded? You can download the map images with [img2dataset](https://github.com/rom1504/img2dataset). ```python from img2dataset import download download( thread_count=64, url_list=".parquet", output_folder="", resize_mode="no", output_format="files", input_format="parquet", url_col="url", caption_col="text", verify_hash=("sha256", "sha256"), ) ``` For Windows users: ```python import multiprocessing as mp from img2dataset import download # a small patch is also needed: https://github.com/rom1504/img2dataset/issues/347 def main(): download(...) if __name__ == "__main__": multiprocessing.freeze_support() main() ``` Note that image links may be broken since the release of the original CommonPool dataset. It is estimated that 2/3 of the images are still available, that is, 50 million potential map images. 5TB of storage are needed when assuming an average image size of 100kB. With a large bandwidth, it may be possible to download the images within 24h. ## How was this dataset created? The dataset is a subset of the [CommonPool dataset (xlarge)](https://huggingface.co/datasets/mlfoundations/datacomp_xlarge), which consists of 10 billion images. To filter the data, a classifier was established based on the embeddings of 1,860 maps and 1,860 non-maps and evaluated on 1,240 maps and 1,240 non-maps. This map dataset has been collected by [Schnürer et al. 2021](https://doi.org/10.1080/00087041.2020.1738112). The embeddings were generated by a pre-trained vision transformer on OpenAI data ([OpenCLIP](https://github.com/mlfoundations/open_clip)). Afterwards, different methods were tested to classify the embeddings: | Model | Accuracy |-----------------------------------------------|---------- | Xception / InceptionResNetV2 (= Baseline) | 96.7 | ViT-L/14 + L2 distance to averaged embeddings | 96.7 | ViT-L/14 + Logistic Regression | 97.9 | ViT-L/14 + MLP (3x256 units) | 98.2 | ViT-L/14 + SVM (polynomial, degree 3) | 98.5 Merely averaging the embeddings and calculating the nearest distance already reached the same accuracy as the two classification networks in [Schnürer et al. 2021](https://doi.org/10.1080/00087041.2020.1738112). Training models from [scikit](https://scikit-learn.org/) to distinguish maps and non-maps increased the validation accuracy even further. The highest accuracy has been achieved with a Support Vector Machine (SVM) with a polynomial kernel. Overall, downloading the CommonPool dataset, separating non-maps and uploading the maps took about 50h for 10 CPUs and 120GB RAM on average as well as caused incoming network traffic of 500MB/s. SVMs are computationally the most demanding model among the examined ones; luckily, the inference speed could be improved by using an [Intel Extension](https://intel.github.io/scikit-learn-intelex). Classifying 500,000 embeddings took about 10 secs. ## What are the limitations? A qualitative inspection of the detected maps in the CommonPool dataset looks promising, however, it is not known what the actual accuracy is. Especially the false negative rate is hard to estimate due to the high number of non-maps among the CommonPool images. Mixtures between natural images and maps (e.g. a map printed on a bag, a map in a park) have not been further examined. Also, duplicates or very similar map images have not been detected. Textual embeddings have not been considered in the separation process so far. The training dataset has a quite large variety of images, however, the textual descriptions may be too specific since the dataset originates only from Pinterest. Also, simply filtering by the word 'map' may lead to false positives as it has many meanings. Nevertheless, the textual embedding space may be explored in the future and possibly help to refine the visual classifier. It is planned to republish the training data and deploy the classification model. ### Citation ``` @inproceedings{Schnürer_MapPool_2024, title={MapPool - Bubbling up an extremely large corpus of maps for AI}, author={Schnürer, Raimund}, year={2024}} ```