|
import csv |
|
import json |
|
import os |
|
from typing import List |
|
import datasets |
|
import logging |
|
from datetime import datetime, timedelta |
|
import pandas as pd |
|
import requests |
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {Singapore Traffic Image Dataset}, |
|
author={huggingface, Inc. |
|
}, |
|
year={2023} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
This dataset contains traffic images from traffic signal cameras of singapore. The images are captured at 1.5 minute interval from 6 pm to 7 pm everyday for the month of January 2024. |
|
""" |
|
|
|
|
|
_HOMEPAGE = "https://beta.data.gov.sg/collections/354/view" |
|
|
|
|
|
|
|
|
|
|
|
class TrafficSignalImages(datasets.GeneratorBasedBuilder): |
|
"""My dataset is in the form of CSV file hosted on my github. It contains traffic images from 1st Jan 2024 to 31st Jan 2024 from 6 to 7 pm everyday. The original code to fetch these images has been commented in the generate_examples function.""" |
|
|
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"timestamp": datasets.Value("string"), |
|
"camera_id": datasets.Value("string"), |
|
"latitude": datasets.Value("float"), |
|
"longitude": datasets.Value("float"), |
|
"image_url": datasets.Image(), |
|
"image_metadata": datasets.Value("string") |
|
} |
|
), |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager: datasets.DownloadManager): |
|
|
|
urls_to_download = { |
|
"csv_file": "https://raw.githubusercontent.com/Sayali-pingle/HuggingFace--Traffic-Image-Dataset/main/camera_data.csv" |
|
} |
|
downloaded_files = dl_manager.download_and_extract(urls_to_download['csv_file']) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"csv_file_path": downloaded_files, |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, csv_file_path): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
camera_data= pd.read_csv(csv_file_path) |
|
|
|
for idx, example in camera_data.iterrows(): |
|
yield idx, { |
|
"timestamp": example["timestamp"], |
|
"camera_id": example["camera_id"], |
|
"latitude": example["latitude"], |
|
"longitude": example["longitude"], |
|
"image_url": example["image_url"], |
|
"image_metadata": example["image_metadata"] |
|
} |
|
|