pytorch_pfn_extras.dataset.tabular.delegate_dataset.DelegateDataset#
- class pytorch_pfn_extras.dataset.tabular.delegate_dataset.DelegateDataset(dataset)#
Bases:
TabularDataset
A helper class to implement a TabularDataset.
This class wraps an instance of
TabularDataset
and provides methods ofTabularDataset
. This class is useful to create a custom dataset class by inheriting it.>>> import numpy as np >>> >>> from pytorch_pfn_extras.dataset import tabular >>> >>> class MyDataset(tabular.DelegateDataset): ... ... def __init__(self): ... super().__init__(tabular.from_data(( ... ('a', np.arange(10)), ... ('b', self.get_b), ... ('c', [3, 1, 4, 5, 9, 2, 6, 8, 7, 0]), ... (('d', 'e'), self.get_de)))) ... ... def get_b(self, i): ... return 'b[{}]'.format(i) ... ... def get_de(self, i): ... return {'d': 'd[{}]'.format(i), 'e': 'e[{}]'.format(i)} ... >>> dataset = MyDataset() >>> len(dataset) 10 >>> dataset.keys ('a', 'b', 'c', 'd', 'e') >>> dataset[0] (0, 'b[0]', 3, 'd[0]', 'e[0]')
- Parameters:
dataset (pytorch_pfn_extras.dataset.TabularDataset) – An underlying dataset.
Methods
__init__
(dataset)asdict
()Return a view with dict mode.
astuple
()Return a view with tuple mode.
concat
(*datasets)Stack datasets along rows.
convert
(data)Convert fetched data.
fetch
()Fetch data.
get_example
(i)get_examples
(indices, key_indices)Return a part of data.
join
(*datasets)Stack datasets along columns.
transform
(keys, transform)Apply a transform to each example.
transform_batch
(keys, transform_batch)Apply a transform to examples.
with_converter
(converter)Override the behaviour of
convert()
.Attributes
Names of columns.
Mode of representation.
slice
Get a slice of dataset.
- __init__(dataset)#
- get_examples(indices, key_indices)#
Return a part of data.
- Parameters:
indices (list of ints or slice) – Indices of requested rows. If this argument is
None
, it indicates all rows.key_indices (tuple of ints) – Indices of requested columns. If this argument is
None
, it indicates all columns.
- Returns:
tuple of lists/arrays
- property keys#
Names of columns.
A tuple of strings that indicate the names of columns.
- property mode#
Mode of representation.
This indicates the type of value returned by
fetch()
and__getitem__()
.tuple
,dict
, andNone
are supported.