-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataset.py
More file actions
30 lines (24 loc) · 754 Bytes
/
dataset.py
File metadata and controls
30 lines (24 loc) · 754 Bytes
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
"""
Dataset for the connect 4 AI
"""
import torch
from torch.utils.data import Dataset
from game import GameState
class GameDataSet(Dataset):
"""
Dataset API
"""
def __init__(self, examples: list[tuple[GameState, list[float], float]]):
self.examples = [
(
a.canonical_representation().to(torch.float32).permute(2, 0, 1),
torch.tensor(b).to(torch.float32),
torch.tensor(c).to(torch.float32),
)
for a, b, c in examples
]
def __len__(self):
return len(self.examples)
def __getitem__(self, idx) -> tuple[torch.Tensor, torch.Tensor, float]:
board, vis, value = self.examples[idx]
return board, vis, value