Generates synthetic input data.
| 27 | |
| 28 | @mod.export() |
| 29 | class DataLoader: |
| 30 | """ |
| 31 | Generates synthetic input data. |
| 32 | """ |
| 33 | |
| 34 | def __init__( |
| 35 | self, seed=None, iterations=None, input_metadata=None, int_range=None, float_range=None, val_range=None |
| 36 | ): |
| 37 | """ |
| 38 | Args: |
| 39 | seed (int): |
| 40 | The seed to use when generating random inputs. |
| 41 | Defaults to ``util.constants.DEFAULT_SEED``. |
| 42 | iterations (int): |
| 43 | The number of iterations for which to supply data. |
| 44 | Defaults to 1. |
| 45 | input_metadata (TensorMetadata): |
| 46 | A mapping of input names to their corresponding shapes and data types. |
| 47 | This will be used to determine what shapes to supply for inputs with dynamic shape, as |
| 48 | well as to set the data type of the generated inputs. |
| 49 | If either dtype or shape are None, then the value will be automatically determined. |
| 50 | For input shape tensors, i.e. inputs whose *value* describes a shape in the model, the |
| 51 | provided shape will be used to populate the values of the inputs, rather than to determine |
| 52 | their shape. |
| 53 | val_range (Union[Tuple[number], Dict[str, Tuple[number]]]): |
| 54 | A tuple containing exactly 2 numbers, indicating the minimum and maximum values (inclusive) |
| 55 | the data loader should generate. |
| 56 | If either value in the tuple is None, the default will be used for that value. |
| 57 | If None is provided instead of a tuple, then the default values will be used for both the |
| 58 | minimum and maximum. |
| 59 | This can be specified on a per-input basis using a dictionary. In that case, |
| 60 | use an empty string ("") as the key to specify default range for inputs not explicitly listed. |
| 61 | Defaults to (0.0, 1.0). |
| 62 | |
| 63 | int_range (Tuple[int]): |
| 64 | [DEPRECATED - Use val_range instead] |
| 65 | A tuple containing exactly 2 integers, indicating the minimum and maximum integer values (inclusive) |
| 66 | the data loader should generate. If either value in the tuple is None, the default will be used |
| 67 | for that value. |
| 68 | If None is provided instead of a tuple, then the default values will be used for both the |
| 69 | minimum and maximum. |
| 70 | float_range (Tuple[float]): |
| 71 | [DEPRECATED - Use val_range instead] |
| 72 | A tuple containing exactly 2 floats, indicating the minimum and maximum float values (inclusive) |
| 73 | the data loader should generate. If either value in the tuple is None, the default will be used |
| 74 | for that value. |
| 75 | If None is provided instead of a tuple, then the default values will be used for both the |
| 76 | minimum and maximum. |
| 77 | """ |
| 78 | |
| 79 | def default_tuple(tup, default): |
| 80 | if tup is None or (not isinstance(tup, tuple) and not isinstance(tup, list)): |
| 81 | return default |
| 82 | new_tup = [] |
| 83 | for elem, default_elem in zip(tup, default): |
| 84 | new_tup.append(util.default(elem, default_elem)) |
| 85 | return tuple(new_tup) |
| 86 |
no outgoing calls