Datasets:
|
Download README.md from codeShare/adcom_captioned_ai_images: direct link, hf CLI and curl.
- Browser
- Download file 8.19 kB
-
https://huggingface.co/datasets/codeShare/adcom_captioned_ai_images/resolve/bbfa355f9eeb74dfd2064dc05f5626ab2ea76a4d/README.md
- Command line
-
hf download hf://datasets/codeShare/adcom_captioned_ai_images@bbfa355f9eeb74dfd2064dc05f5626ab2ea76a4d/README.md
-
curl -L -o README.md https://huggingface.co/datasets/codeShare/adcom_captioned_ai_images/resolve/bbfa355f9eeb74dfd2064dc05f5626ab2ea76a4d/README.md
8.19 kB
| pretty_name: Adcom Captioned AI Images | |
| tags: | |
| - images | |
| - captions | |
| - ai-generated-images | |
| - natural-language | |
| license: apache-2.0 | |
| language: | |
| - en | |
| # ADCOM Captioned AI Images | |
| ## Dataset description | |
| Adcom's captioned AI Images is a collection of images paired with associated | |
| captioning and descriptive metadata. | |
| The repository uses an indexed storage layout designed to make image retrieval | |
| more efficient. Instead of storing all image data directly inside a single | |
| metadata file, it separates the metadata index from the image data. | |
| The dataset consists of: | |
| - A Parquet metadata index: `captions.parquet` | |
| - JSONL image shards containing the image data | |
| - Byte offsets and record lengths in the Parquet index for direct image access | |
| This layout allows users to retrieve individual images without downloading | |
| and scanning every image shard. | |
| ## Repository structure | |
| ```text | |
| adcom_captioned_ai_images/ | |
| │ | |
| ├── README.md | |
| ├── captions.parquet | |
| │ | |
| └── [JSONL image shards] | |
| ├── ... | |
| └── ... | |
| ``` | |
| The exact shard paths are stored in the `json_file` column of | |
| `captions.parquet`. Use those paths rather than assuming fixed shard names. | |
| ### 1. Metadata index: `captions.parquet` | |
| The Parquet file contains one metadata/index row per image. | |
| | Column | Description | | |
| |---|---| | |
| | `idx` | Image identifier | | |
| | `prompt` | Text prompt or caption associated with the image | | |
| | `tags` | Descriptive tags associated with the image | | |
| | `author` | Author or contributor | | |
| | `json_file` | Repository-relative path to the JSONL shard containing the image | | |
| | `byte_offset` | Zero-based byte offset of the JSONL record within that shard | | |
| | `byte_length` | Number of bytes to read for that record | | |
| The index columns `json_file`, `byte_offset`, and `byte_length` are used | |
| together to locate an image record directly. | |
| Offsets and lengths refer to bytes, not character positions. | |
| ### 2. Image data: JSONL shards | |
| Images are stored in JSONL files. Each line represents an individual image | |
| record encoded as JSON. | |
| A record has the following structure: | |
| ```json | |
| { | |
| "idx": "IMAGE_ID", | |
| "image": "data:image/png;base64,..." | |
| } | |
| ``` | |
| The `image` field contains a base64-encoded image, commonly represented as | |
| a data URI. Consumers should also allow for a raw base64 string. | |
| The `idx` field identifies the image and corresponds to the `idx` value in | |
| the Parquet index. | |
| ### 3. How indexed retrieval works | |
| For an image with a given `idx`: | |
| 1. Find its row in `captions.parquet`. | |
| 2. Read the row's `json_file`, `byte_offset`, and `byte_length`. | |
| 3. Download the referenced JSONL shard. | |
| 4. Seek to `byte_offset` in binary mode. | |
| 5. Read `byte_length` bytes. | |
| 6. Parse the JSON record and decode its base64 image. | |
| This avoids scanning the entire shard for the selected image. | |
| --- | |
| ## Quick start | |
| ### Install dependencies | |
| ```bash | |
| pip install pandas pyarrow pillow huggingface_hub | |
| ``` | |
| ### Load the metadata index | |
| ```python | |
| import pandas as pd | |
| from huggingface_hub import hf_hub_download | |
| REPO_ID = "codeShare/adcom_captioned_ai_images" | |
| parquet_path = hf_hub_download( | |
| repo_id=REPO_ID, | |
| filename="captions.parquet", | |
| repo_type="dataset" | |
| ) | |
| metadata = pd.read_parquet(parquet_path) | |
| print(metadata.head()) | |
| print(f"Total indexed images: {len(metadata):,}") | |
| ``` | |
| For a private or gated repository, authenticate with a Hugging Face | |
| access token and pass it as the `token` argument to `hf_hub_download`. | |
| ### Retrieve one image by ID | |
| This example downloads only the shard containing the requested image and | |
| reads only the indexed record. | |
| ```python | |
| import json | |
| import base64 | |
| import re | |
| import io | |
| import pandas as pd | |
| from PIL import Image | |
| from huggingface_hub import hf_hub_download | |
| REPO_ID = "codeShare/adcom_captioned_ai_images" | |
| # Load the metadata index. | |
| parquet_path = hf_hub_download( | |
| repo_id=REPO_ID, | |
| filename="captions.parquet", | |
| repo_type="dataset" | |
| ) | |
| metadata = pd.read_parquet(parquet_path) | |
| # Choose an image ID from the index. | |
| target_idx = str(metadata.iloc[0]["idx"]) | |
| # Find its index entry. | |
| row = metadata.loc[ | |
| metadata["idx"].astype(str) == target_idx | |
| ].iloc[0] | |
| # Download only the required shard. | |
| shard_path = hf_hub_download( | |
| repo_id=REPO_ID, | |
| filename=str(row["json_file"]), | |
| repo_type="dataset" | |
| ) | |
| # Read the exact JSONL record using its byte location. | |
| with open(shard_path, "rb") as f: | |
| f.seek(int(row["byte_offset"])) | |
| raw_record = f.read(int(row["byte_length"])) | |
| record = json.loads(raw_record.decode("utf-8")) | |
| # Verify the retrieved record. | |
| assert str(record["idx"]) == target_idx | |
| # Decode the image. | |
| image_value = record["image"].strip() | |
| if image_value.startswith("data:") and "," in image_value: | |
| image_value = image_value.split(",", 1)[1] | |
| image_value = re.sub(r"\s+", "", image_value) | |
| image_bytes = base64.b64decode(image_value) | |
| image = Image.open(io.BytesIO(image_bytes)).convert("RGB") | |
| display(image) | |
| print("Image ID:", target_idx) | |
| print("Prompt:", row["prompt"]) | |
| print("Author:", row["author"]) | |
| print("Tags:", row["tags"]) | |
| ``` | |
| ### Retrieve a random sample of images | |
| The following example samples metadata first and downloads only the shards | |
| needed for the selected images. | |
| ```python | |
| import json | |
| import base64 | |
| import re | |
| import io | |
| import pandas as pd | |
| from PIL import Image | |
| from huggingface_hub import hf_hub_download | |
| REPO_ID = "codeShare/adcom_captioned_ai_images" | |
| NUM_SAMPLES = 10 | |
| RANDOM_SEED = 42 | |
| # Load the index. | |
| parquet_path = hf_hub_download( | |
| repo_id=REPO_ID, | |
| filename="captions.parquet", | |
| repo_type="dataset" | |
| ) | |
| metadata = pd.read_parquet(parquet_path) | |
| # Optional author filter. | |
| # Set to None to include all authors. | |
| AUTHOR_FILTER = "Adcom" | |
| if AUTHOR_FILTER is not None: | |
| metadata = metadata[ | |
| metadata["author"].fillna("").astype(str).str.casefold() | |
| == AUTHOR_FILTER.casefold() | |
| ] | |
| if metadata.empty: | |
| raise ValueError("No matching records found.") | |
| # Reproducible random sample. | |
| sampled = metadata.sample( | |
| n=min(NUM_SAMPLES, len(metadata)), | |
| random_state=RANDOM_SEED | |
| ) | |
| # Download only the shards required by the sample. | |
| shard_cache = {} | |
| for _, row in sampled.iterrows(): | |
| shard_name = str(row["json_file"]) | |
| if shard_name not in shard_cache: | |
| shard_cache[shard_name] = hf_hub_download( | |
| repo_id=REPO_ID, | |
| filename=shard_name, | |
| repo_type="dataset" | |
| ) | |
| # Retrieve the indexed JSONL record. | |
| with open(shard_cache[shard_name], "rb") as f: | |
| f.seek(int(row["byte_offset"])) | |
| raw_record = f.read(int(row["byte_length"])) | |
| record = json.loads(raw_record.decode("utf-8")) | |
| if str(record["idx"]) != str(row["idx"]): | |
| raise ValueError("Image ID does not match the metadata index.") | |
| # Decode image data. | |
| image_value = record["image"].strip() | |
| if image_value.startswith("data:") and "," in image_value: | |
| image_value = image_value.split(",", 1)[1] | |
| image_value = re.sub(r"\s+", "", image_value) | |
| image_bytes = base64.b64decode(image_value) | |
| image = Image.open(io.BytesIO(image_bytes)).convert("RGB") | |
| print("Image ID:", row["idx"]) | |
| print("Prompt:", row["prompt"]) | |
| print("Author:", row["author"]) | |
| display(image) | |
| image.close() | |
| ``` | |
| --- | |
| ## Performance notes | |
| - **Metadata-first sampling:** Select records from the Parquet index before downloading image data. | |
| - **Selective shard downloads:** Only download shards referenced by the selected records. | |
| - **Direct record access:** Use byte offsets and lengths instead of scanning JSONL files. | |
| - **Reproducible sampling:** Set `random_state` to a fixed integer to reproduce a sample. | |
| - **Private repository support:** Pass a Hugging Face token to the download functions when authentication is required. | |
| ## Important notes | |
| - The Parquet index and JSONL shards must remain consistent. If shard contents are rewritten or reordered, the corresponding byte offsets and lengths must be regenerated. | |
| - Image data is stored as base64 in JSONL records; it is decoded into image bytes when retrieved. | |
| - The dataset card does not declare a license. Please consult the dataset owner for licensing and usage permissions before redistributing or using the data commercially. |