Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import torch
2from fastai.data.block import TransformBlock
3import numpy as np
5def bool_to_tensor(value: bool):
6 return torch.FloatTensor(value)
9def unsqueeze(inputs):
10 """This is needed to transform the input with an extra dimension added to the end of the tensor."""
11 return inputs.unsqueeze(dim=-1).float()
14def BoolBlock(**kwargs):
15 return TransformBlock(
16 item_tfms=[bool_to_tensor],
17 batch_tfms=unsqueeze,
18 **kwargs
19 )
22def float64_to_32(value: np.float64):
23 return np.float32(value)
26def Float32Block(**kwargs):
27 return TransformBlock(
28 item_tfms=[float64_to_32],
29 **kwargs
30 )