chesscog.core.dataset package¶
Module for handling datasets.
Submodules¶
chesscog.core.dataset.dataset module¶
Methods specific to handling chess datasets.
- chesscog.core.dataset.dataset.build_data_loader(cfg: recap.config.CfgNode, dataset: torch.utils.data.dataset.Dataset, mode: chesscog.core.dataset.datasets.Datasets) torch.utils.data.dataloader.DataLoader ¶
Build a data loader for a dataset.
- Parameters
cfg (CN) – the config object
dataset (torch.utils.data.Dataset) – the dataset
mode (Datasets) – the split
- Returns
the data loader
- Return type
torch.utils.data.DataLoader
- chesscog.core.dataset.dataset.build_dataset(cfg: recap.config.CfgNode, mode: chesscog.core.dataset.datasets.Datasets) torch.utils.data.dataset.Dataset ¶
Build a dataset from its configuration.
- Parameters
cfg (CN) – the config object
mode (Datasets) – the split (important to figure out which transforms to apply)
- Returns
the dataset
- Return type
torch.utils.data.Dataset
- chesscog.core.dataset.dataset.color_name(color: bool) str ¶
Convert a chess color to a string.
- Parameters
color (chess.Color) – the color
- Returns
the string representation
- Return type
str
- chesscog.core.dataset.dataset.name_to_piece(name: str) chess.Piece ¶
Convert the name of a piece to an instance of
chess.Piece
.- Parameters
name (str) – the name of the piece
- Returns
the instance of
chess.Piece
- Return type
chess.Piece
- chesscog.core.dataset.dataset.piece_name(piece: chess.Piece) str ¶
Convert a chess piece to a string.
- Parameters
piece (chess.Piece) – the piece
- Returns
the corresponding string
- Return type
str
chesscog.core.dataset.datasets module¶
chesscog.core.dataset.transforms module¶
- class chesscog.core.dataset.transforms.Scale(horizontal: Optional[Union[float, tuple]], vertical: Optional[Union[float, tuple]])¶
Bases:
chesscog.core.dataset.transforms._HVTransform
Custom scaling transform where the horizontal and vertical scales can independently be specified.
The center of scaling is the bottom left of the image (this makes particular sense for the piece classifier).
- class chesscog.core.dataset.transforms.Shear(amount: Optional[Union[tuple, float, int]])¶
Bases:
object
Custom shear transform that keeps the bottom of the image invariant because for piece classification, we only want to “tilt” the top of the image.
- class chesscog.core.dataset.transforms.Translate(horizontal: Optional[Union[float, tuple]], vertical: Optional[Union[float, tuple]])¶
Bases:
chesscog.core.dataset.transforms._HVTransform
Custom translation transform for convenience.
- chesscog.core.dataset.transforms.build_transforms(cfg: recap.config.CfgNode, mode: chesscog.core.dataset.datasets.Datasets) Callable ¶
Build the transforms for a dataset.
- Parameters
cfg (CN) – the config object
mode (Datasets) – the dataset split
- Returns
the transform function
- Return type
typing.Callable
- chesscog.core.dataset.transforms.unnormalize(x: Union[torch.Tensor, numpy.ndarray]) Union[torch.Tensor, numpy.ndarray] ¶
Unnormalize an input image.
It must be of the form ([…, W, H, 3]).
- Parameters
x (typing.Union[torch.Tensor, np.ndarray]) – the input tensor/array representing the image
- Returns
the unnormalized image
- Return type
typing.Union[torch.Tensor, np.ndarray]