Upload risk_biased_dataset.py
Browse files- risk_biased_dataset.py +27 -1
risk_biased_dataset.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
import datasets
|
|
|
|
|
|
|
2 |
|
3 |
_DESCRIPTION = """\
|
4 |
Dataset of pre-processed samples from a small portion of the \
|
@@ -60,4 +63,27 @@ class RiskBiasedDataset(datasets.Dataset):
|
|
60 |
supervised_keys=None,
|
61 |
homepage="https://sites.google.com/d/1cwohIm9fzTZEPAo7b_Di4h9iNgMiKHRo/p/1nPdTBSee6E40dmUXNyqxzUtb4_NnkI_6/edit",
|
62 |
citation=_CITATION,
|
63 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import datasets
|
2 |
+
import json
|
3 |
+
import numpy
|
4 |
+
import torch
|
5 |
|
6 |
_DESCRIPTION = """\
|
7 |
Dataset of pre-processed samples from a small portion of the \
|
|
|
63 |
supervised_keys=None,
|
64 |
homepage="https://sites.google.com/d/1cwohIm9fzTZEPAo7b_Di4h9iNgMiKHRo/p/1nPdTBSee6E40dmUXNyqxzUtb4_NnkI_6/edit",
|
65 |
citation=_CITATION,
|
66 |
+
)
|
67 |
+
|
68 |
+
def _generate_examples(self, filepath):
|
69 |
+
"""Yields examples."""
|
70 |
+
with open(filepath, "r") as f:
|
71 |
+
data = json.load(f)
|
72 |
+
|
73 |
+
x = torch.from_numpy(numpy.array(data["x"]).astype(numpy.float32))
|
74 |
+
mask_x = torch.from_numpy(numpy.array(data["mask_x"]).astype(numpy.bool8))
|
75 |
+
y = torch.from_numpy(numpy.array(data["y"]).astype(numpy.float32))
|
76 |
+
mask_y = torch.from_numpy(numpy.array(data["mask_y"]).astype(numpy.bool8))
|
77 |
+
mask_loss = torch.from_numpy( numpy.array(data["mask_loss"]).astype(numpy.bool8))
|
78 |
+
map_data = torch.from_numpy(numpy.array(data["map_data"]).astype(numpy.float32))
|
79 |
+
mask_map = torch.from_numpy(numpy.array(data["mask_map"]).astype(numpy.bool8))
|
80 |
+
offset = torch.from_numpy(numpy.array(data["offset"]).astype(numpy.float32))
|
81 |
+
x_ego = torch.from_numpy(numpy.array(data["x_ego"]).astype(numpy.float32))
|
82 |
+
y_ego = torch.from_numpy(numpy.array(data["y_ego"]).astype(numpy.float32))
|
83 |
+
|
84 |
+
batch_size = x.shape[0]
|
85 |
+
|
86 |
+
for i in range(batch_size):
|
87 |
+
yield x, mask_x, y, mask_y, mask_loss, map_data, mask_map, offset, x_ego, y_ego
|
88 |
+
|
89 |
+
|