Datasets:
File size: 4,900 Bytes
2479dcf 6eac4da 2479dcf 6eac4da e58caee 2479dcf 6eac4da 2479dcf 6eac4da 2479dcf 6eac4da 2479dcf |
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 138 139 140 |
"""Open Cortex FX v3 Dataset."""
import csv
import io
import zipfile
from pathlib import Path
from typing import Iterator
import datasets
_DESCRIPTION = """\
Open Cortex FX v3 is a video dataset focusing on human manual labor and physical work activities.
Each video has been carefully annotated to identify work-related content and categorized into specific labor types.
"""
_HOMEPAGE = "https://huggingface.co/datasets/Standout/open-cortex-fx-v3"
_LICENSE = "Apache 2.0"
_CITATION = """\
@dataset{open_cortex_fx_v3,
title={Open Cortex FX v3: A Classified Dataset of Human Manual Labor},
author={Standout},
year={2024},
url={https://huggingface.co/datasets/Standout/open-cortex-fx-v3}
}
"""
class OpenCortexFXv3(datasets.GeneratorBasedBuilder):
"""Open Cortex FX v3 Dataset."""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="default",
version=VERSION,
description="Open Cortex FX v3 dataset",
),
]
DEFAULT_CONFIG_NAME = "default"
def _info(self) -> datasets.DatasetInfo:
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"name": datasets.Value("string"),
"category": datasets.Value("string"),
"split": datasets.Value("string"),
"video": datasets.Value("binary"),
}
),
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager: datasets.DownloadManager):
"""Returns SplitGenerators."""
# Define splits based on available zip files
# We'll create splits for final_0 through final_5 (can be extended)
splits = []
for i in range(6): # We have 6 splits (final_0 through final_5)
split_name = f"final_{i}"
zip_url = f"https://huggingface.co/datasets/Standout/open-cortex-fx-v3/resolve/main/final_{i}.zip"
try:
zip_path = dl_manager.download(zip_url)
if zip_path and Path(zip_path).exists():
splits.append(
datasets.SplitGenerator(
name=datasets.Split(split_name),
gen_kwargs={"zip_path": Path(zip_path)},
)
)
except Exception:
# Skip if file doesn't exist
continue
# If no splits found, return at least one to avoid errors
if not splits:
# Fallback: try to find any zip file
data_dir = Path(dl_manager.download_and_extract("https://huggingface.co/datasets/Standout/open-cortex-fx-v3/tree/main"))
zip_files = sorted(data_dir.glob("final_*.zip"))
for zip_file in zip_files:
split_name = zip_file.stem
splits.append(
datasets.SplitGenerator(
name=datasets.Split(split_name),
gen_kwargs={"zip_path": zip_file},
)
)
return splits
def _generate_examples(self, zip_path: Path) -> Iterator[tuple[int, dict]]:
"""Yields examples."""
with zipfile.ZipFile(zip_path, "r") as z:
# Read metadata
try:
with z.open("metadata.csv") as f:
content = f.read().decode("utf-8")
reader = csv.DictReader(io.StringIO(content))
metadata = list(reader)
except KeyError:
# If metadata.csv not found, skip this split
return
# Get split name from zip filename
split_name = zip_path.stem
for idx, row in enumerate(metadata):
video_name = row["name"]
category = row["category"]
# Find video in zip - try different path formats
video_paths = [
f"{category}/{video_name}",
f"{category.replace(' ', '_')}/{video_name}",
video_name, # Fallback to root
]
video_data = None
for video_path in video_paths:
try:
video_data = z.read(video_path)
break
except KeyError:
continue
if video_data:
yield idx, {
"name": video_name,
"category": category,
"split": split_name,
"video": video_data,
}
|