Datasets:
Upload open_cortex_fx_v3.py with huggingface_hub
Browse files- open_cortex_fx_v3.py +121 -0
open_cortex_fx_v3.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Open Cortex FX v3 Dataset."""
|
| 2 |
+
|
| 3 |
+
import csv
|
| 4 |
+
import io
|
| 5 |
+
import zipfile
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Iterator
|
| 8 |
+
|
| 9 |
+
import datasets
|
| 10 |
+
|
| 11 |
+
_DESCRIPTION = """\
|
| 12 |
+
Open Cortex FX v3 is a video dataset focusing on human manual labor and physical work activities.
|
| 13 |
+
Each video has been carefully annotated to identify work-related content and categorized into specific labor types.
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
_HOMEPAGE = "https://huggingface.co/datasets/Standout/open-cortex-fx-v3"
|
| 17 |
+
|
| 18 |
+
_LICENSE = "Apache 2.0"
|
| 19 |
+
|
| 20 |
+
_CITATION = """\
|
| 21 |
+
@dataset{open_cortex_fx_v3,
|
| 22 |
+
title={Open Cortex FX v3: A Classified Dataset of Human Manual Labor},
|
| 23 |
+
author={Standout},
|
| 24 |
+
year={2024},
|
| 25 |
+
url={https://huggingface.co/datasets/Standout/open-cortex-fx-v3}
|
| 26 |
+
}
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class OpenCortexFXv3(datasets.GeneratorBasedBuilder):
|
| 31 |
+
"""Open Cortex FX v3 Dataset."""
|
| 32 |
+
|
| 33 |
+
VERSION = datasets.Version("1.0.0")
|
| 34 |
+
|
| 35 |
+
BUILDER_CONFIGS = [
|
| 36 |
+
datasets.BuilderConfig(
|
| 37 |
+
name="default",
|
| 38 |
+
version=VERSION,
|
| 39 |
+
description="Open Cortex FX v3 dataset",
|
| 40 |
+
),
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
DEFAULT_CONFIG_NAME = "default"
|
| 44 |
+
|
| 45 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 46 |
+
return datasets.DatasetInfo(
|
| 47 |
+
description=_DESCRIPTION,
|
| 48 |
+
features=datasets.Features(
|
| 49 |
+
{
|
| 50 |
+
"name": datasets.Value("string"),
|
| 51 |
+
"category": datasets.Value("string"),
|
| 52 |
+
"split": datasets.Value("string"),
|
| 53 |
+
"video": datasets.Value("binary"),
|
| 54 |
+
}
|
| 55 |
+
),
|
| 56 |
+
homepage=_HOMEPAGE,
|
| 57 |
+
license=_LICENSE,
|
| 58 |
+
citation=_CITATION,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
| 62 |
+
"""Returns SplitGenerators."""
|
| 63 |
+
data_dir = dl_manager.download_and_extract("https://huggingface.co/datasets/Standout/open-cortex-fx-v3/resolve/main/")
|
| 64 |
+
|
| 65 |
+
# Find all zip files
|
| 66 |
+
zip_files = sorted(Path(data_dir).glob("final_*.zip"))
|
| 67 |
+
|
| 68 |
+
splits = []
|
| 69 |
+
for zip_file in zip_files:
|
| 70 |
+
split_name = zip_file.stem # e.g., "final_0"
|
| 71 |
+
splits.append(
|
| 72 |
+
datasets.SplitGenerator(
|
| 73 |
+
name=datasets.Split(split_name),
|
| 74 |
+
gen_kwargs={"zip_path": zip_file},
|
| 75 |
+
)
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
return splits
|
| 79 |
+
|
| 80 |
+
def _generate_examples(self, zip_path: Path) -> Iterator[tuple[int, dict]]:
|
| 81 |
+
"""Yields examples."""
|
| 82 |
+
with zipfile.ZipFile(zip_path, "r") as z:
|
| 83 |
+
# Read metadata
|
| 84 |
+
with z.open("metadata.csv") as f:
|
| 85 |
+
content = f.read().decode("utf-8")
|
| 86 |
+
reader = csv.DictReader(io.StringIO(content))
|
| 87 |
+
metadata = list(reader)
|
| 88 |
+
|
| 89 |
+
# Get split name from zip filename
|
| 90 |
+
split_name = zip_path.stem
|
| 91 |
+
|
| 92 |
+
for idx, row in enumerate(metadata):
|
| 93 |
+
video_name = row["name"]
|
| 94 |
+
category = row["category"]
|
| 95 |
+
|
| 96 |
+
# Find video in zip
|
| 97 |
+
video_path_in_zip = f"{category}/{video_name}"
|
| 98 |
+
|
| 99 |
+
try:
|
| 100 |
+
video_data = z.read(video_path_in_zip)
|
| 101 |
+
yield idx, {
|
| 102 |
+
"name": video_name,
|
| 103 |
+
"category": category,
|
| 104 |
+
"split": split_name,
|
| 105 |
+
"video": video_data,
|
| 106 |
+
}
|
| 107 |
+
except KeyError:
|
| 108 |
+
# Try alternative path format
|
| 109 |
+
video_path_in_zip = video_path_in_zip.replace(" ", "_")
|
| 110 |
+
try:
|
| 111 |
+
video_data = z.read(video_path_in_zip)
|
| 112 |
+
yield idx, {
|
| 113 |
+
"name": video_name,
|
| 114 |
+
"category": category,
|
| 115 |
+
"split": split_name,
|
| 116 |
+
"video": video_data,
|
| 117 |
+
}
|
| 118 |
+
except KeyError:
|
| 119 |
+
# Skip if video not found
|
| 120 |
+
continue
|
| 121 |
+
|