Upload 2 files
Browse files- dataset_info.json +90 -0
- load_i2e_datasets.py +44 -19
dataset_info.json
CHANGED
|
@@ -597,6 +597,51 @@
|
|
| 597 |
"download_size": 1165568633,
|
| 598 |
"dataset_size": 3076928106
|
| 599 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 600 |
"I2E-ImageNet": {
|
| 601 |
"features": [
|
| 602 |
{
|
|
@@ -1632,6 +1677,51 @@
|
|
| 1632 |
"download_size": 57961329620,
|
| 1633 |
"dataset_size": 133825742994
|
| 1634 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1635 |
"I2E-Mini-ImageNet": {
|
| 1636 |
"features": [
|
| 1637 |
{
|
|
|
|
| 597 |
"download_size": 1165568633,
|
| 598 |
"dataset_size": 3076928106
|
| 599 |
},
|
| 600 |
+
"I2E-FashionMNIST": {
|
| 601 |
+
"features": [
|
| 602 |
+
{
|
| 603 |
+
"name": "file_path",
|
| 604 |
+
"dtype": "string"
|
| 605 |
+
},
|
| 606 |
+
{
|
| 607 |
+
"name": "label",
|
| 608 |
+
"dtype": {
|
| 609 |
+
"class_label": {
|
| 610 |
+
"names": {
|
| 611 |
+
"0": "0",
|
| 612 |
+
"1": "1",
|
| 613 |
+
"2": "2",
|
| 614 |
+
"3": "3",
|
| 615 |
+
"4": "4",
|
| 616 |
+
"5": "5",
|
| 617 |
+
"6": "6",
|
| 618 |
+
"7": "7",
|
| 619 |
+
"8": "8",
|
| 620 |
+
"9": "9"
|
| 621 |
+
}
|
| 622 |
+
}
|
| 623 |
+
}
|
| 624 |
+
},
|
| 625 |
+
{
|
| 626 |
+
"name": "data",
|
| 627 |
+
"dtype": "binary"
|
| 628 |
+
}
|
| 629 |
+
],
|
| 630 |
+
"splits": [
|
| 631 |
+
{
|
| 632 |
+
"name": "train",
|
| 633 |
+
"num_bytes": 132648890,
|
| 634 |
+
"num_examples": 60000
|
| 635 |
+
},
|
| 636 |
+
{
|
| 637 |
+
"name": "validation",
|
| 638 |
+
"num_bytes": 22098890,
|
| 639 |
+
"num_examples": 10000
|
| 640 |
+
}
|
| 641 |
+
],
|
| 642 |
+
"download_size": 68196022,
|
| 643 |
+
"dataset_size": 154747780
|
| 644 |
+
},
|
| 645 |
"I2E-ImageNet": {
|
| 646 |
"features": [
|
| 647 |
{
|
|
|
|
| 1677 |
"download_size": 57961329620,
|
| 1678 |
"dataset_size": 133825742994
|
| 1679 |
},
|
| 1680 |
+
"I2E-MNIST": {
|
| 1681 |
+
"features": [
|
| 1682 |
+
{
|
| 1683 |
+
"name": "file_path",
|
| 1684 |
+
"dtype": "string"
|
| 1685 |
+
},
|
| 1686 |
+
{
|
| 1687 |
+
"name": "label",
|
| 1688 |
+
"dtype": {
|
| 1689 |
+
"class_label": {
|
| 1690 |
+
"names": {
|
| 1691 |
+
"0": "0",
|
| 1692 |
+
"1": "1",
|
| 1693 |
+
"2": "2",
|
| 1694 |
+
"3": "3",
|
| 1695 |
+
"4": "4",
|
| 1696 |
+
"5": "5",
|
| 1697 |
+
"6": "6",
|
| 1698 |
+
"7": "7",
|
| 1699 |
+
"8": "8",
|
| 1700 |
+
"9": "9"
|
| 1701 |
+
}
|
| 1702 |
+
}
|
| 1703 |
+
}
|
| 1704 |
+
},
|
| 1705 |
+
{
|
| 1706 |
+
"name": "data",
|
| 1707 |
+
"dtype": "binary"
|
| 1708 |
+
}
|
| 1709 |
+
],
|
| 1710 |
+
"splits": [
|
| 1711 |
+
{
|
| 1712 |
+
"name": "train",
|
| 1713 |
+
"num_bytes": 132648890,
|
| 1714 |
+
"num_examples": 60000
|
| 1715 |
+
},
|
| 1716 |
+
{
|
| 1717 |
+
"name": "validation",
|
| 1718 |
+
"num_bytes": 22098890,
|
| 1719 |
+
"num_examples": 10000
|
| 1720 |
+
}
|
| 1721 |
+
],
|
| 1722 |
+
"download_size": 60473109,
|
| 1723 |
+
"dataset_size": 154747780
|
| 1724 |
+
},
|
| 1725 |
"I2E-Mini-ImageNet": {
|
| 1726 |
"features": [
|
| 1727 |
{
|
load_i2e_datasets.py
CHANGED
|
@@ -2,35 +2,42 @@ import io
|
|
| 2 |
import torch
|
| 3 |
import numpy as np
|
| 4 |
from datasets import load_dataset
|
| 5 |
-
from torch.utils.data import Dataset
|
| 6 |
|
| 7 |
-
|
| 8 |
-
#
|
| 9 |
-
#
|
| 10 |
-
# =================================================
|
| 11 |
def unpack_event_data(item, use_io=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
if use_io:
|
| 13 |
with io.BytesIO(item['data']) as f:
|
| 14 |
raw_data = np.load(f)
|
| 15 |
else:
|
| 16 |
raw_data = np.load(item)
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
packed_body = raw_data[header_size:]
|
| 22 |
-
unpacked = np.unpackbits(packed_body)
|
| 23 |
|
| 24 |
-
num_elements = np.prod(original_shape)
|
| 25 |
event_flat = unpacked[:num_elements]
|
|
|
|
| 26 |
|
| 27 |
-
event_data = event_flat.reshape(original_shape).astype(np.float32).copy() # Reshape and convert to Float Tensor
|
| 28 |
return torch.from_numpy(event_data)
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
class I2E_Dataset(Dataset):
|
| 32 |
-
def __init__(self, cache_dir,
|
| 33 |
-
|
|
|
|
| 34 |
self.transform = transform
|
| 35 |
self.target_transform = target_transform
|
| 36 |
|
|
@@ -39,12 +46,30 @@ class I2E_Dataset(Dataset):
|
|
| 39 |
|
| 40 |
def __getitem__(self, idx):
|
| 41 |
item = self.ds[idx]
|
| 42 |
-
event = unpack_event_data(item)
|
| 43 |
label = item['label']
|
| 44 |
-
|
| 45 |
if self.transform:
|
| 46 |
event = self.transform(event)
|
| 47 |
if self.target_transform:
|
| 48 |
label = self.target_transform(label)
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
import numpy as np
|
| 4 |
from datasets import load_dataset
|
| 5 |
+
from torch.utils.data import Dataset, DataLoader
|
| 6 |
|
| 7 |
+
# ==================================================================
|
| 8 |
+
# 1. Core Decoding Function (Handles the binary packing)
|
| 9 |
+
# ==================================================================
|
|
|
|
| 10 |
def unpack_event_data(item, use_io=True):
|
| 11 |
+
"""
|
| 12 |
+
Decodes the custom binary format:
|
| 13 |
+
Header (8 bytes) -> Shape (T, C, H, W) -> Body (Packed Bits)
|
| 14 |
+
"""
|
| 15 |
if use_io:
|
| 16 |
with io.BytesIO(item['data']) as f:
|
| 17 |
raw_data = np.load(f)
|
| 18 |
else:
|
| 19 |
raw_data = np.load(item)
|
| 20 |
+
|
| 21 |
+
header_size = 4 * 2 # Parse Header (First 8 bytes for 4 uint16 shape values)
|
| 22 |
+
shape_header = raw_data[:header_size].view(np.uint16)
|
| 23 |
+
original_shape = tuple(shape_header) # Returns (T, C, H, W)
|
| 24 |
|
| 25 |
+
packed_body = raw_data[header_size:] # Parse Body & Bit-unpacking
|
| 26 |
+
unpacked = np.unpackbits(packed_body)
|
| 27 |
|
| 28 |
+
num_elements = np.prod(original_shape) # Extract valid bits (Handle padding)
|
| 29 |
event_flat = unpacked[:num_elements]
|
| 30 |
+
event_data = event_flat.reshape(original_shape).astype(np.float32).copy()
|
| 31 |
|
|
|
|
| 32 |
return torch.from_numpy(event_data)
|
| 33 |
|
| 34 |
+
# ==================================================================
|
| 35 |
+
# 2. Dataset Wrapper
|
| 36 |
+
# ==================================================================
|
| 37 |
class I2E_Dataset(Dataset):
|
| 38 |
+
def __init__(self, cache_dir, config_name, split='train', transform=None, target_transform=None):
|
| 39 |
+
print(f"🚀 Loading {config_name} [{split}] from Hugging Face...")
|
| 40 |
+
self.ds = load_dataset('UESTC-BICS/I2E', config_name, split=split, cache_dir=cache_dir, keep_in_memory=False)
|
| 41 |
self.transform = transform
|
| 42 |
self.target_transform = target_transform
|
| 43 |
|
|
|
|
| 46 |
|
| 47 |
def __getitem__(self, idx):
|
| 48 |
item = self.ds[idx]
|
| 49 |
+
event = unpack_event_data(item)
|
| 50 |
label = item['label']
|
|
|
|
| 51 |
if self.transform:
|
| 52 |
event = self.transform(event)
|
| 53 |
if self.target_transform:
|
| 54 |
label = self.target_transform(label)
|
| 55 |
+
return event, label
|
| 56 |
+
|
| 57 |
+
# ==================================================================
|
| 58 |
+
# 3. Run Example
|
| 59 |
+
# ==================================================================
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
import os
|
| 62 |
+
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com' # Use HF mirror server in some regions
|
| 63 |
+
|
| 64 |
+
DATASET_NAME = 'I2E-CIFAR10' # Choose your config: 'I2E-CIFAR10', 'I2E-ImageNet', etc.
|
| 65 |
+
MODEL_PATH = 'Your cache path here' # e.g., './hf_datasets_cache/'
|
| 66 |
+
|
| 67 |
+
train_dataset = I2E_Dataset(MODEL_PATH, DATASET_NAME, split='train')
|
| 68 |
+
val_dataset = I2E_Dataset(MODEL_PATH, DATASET_NAME, split='validation')
|
| 69 |
+
|
| 70 |
+
train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True, num_workers=32, persistent_workers=True)
|
| 71 |
+
val_loader = DataLoader(val_dataset, batch_size=32, shuffle=False, num_workers=32, persistent_workers=True)
|
| 72 |
+
|
| 73 |
+
events, labels = next(iter(train_loader))
|
| 74 |
+
print(f"✅ Loaded Batch Shape: {events.shape}") # Expect: [32, T, 2, H, W]
|
| 75 |
+
print(f"✅ Labels: {labels}")
|