objax.util package¶
objax.util¶
|
Custom dictionary that allows to access dict values as attributes. |
|
Objax to Tensorflow converter, which converts Objax module to tf.Module. |
|
Helper class for renaming string contents. |
|
Returns the indexes of variable names of a function. |
Empty Context Manager. |
|
|
Integer log2. |
Returns the ordered names of the positional arguments of a function. |
|
|
Converts input to tuple. |
- class objax.util.EasyDict(*args, **kwargs)[source]¶
Custom dictionary that allows to access dict values as attributes.
- clear() None. Remove all items from D. ¶
- copy() a shallow copy of D ¶
- fromkeys(value=None, /)¶
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If key is not found, d is returned if given, otherwise KeyError is raised
- popitem() (k, v), remove and return some (key, value) pair as a ¶
2-tuple; but raise KeyError if D is empty.
- setdefault(key, default=None, /)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F. ¶
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values ¶
- class objax.util.Objax2Tf(module)[source]¶
Objax to Tensorflow converter, which converts Objax module to tf.Module.
- Parameters
module (objax.module.Module) –
- __init__(module)[source]¶
Create a Tensorflow module from Objax module.
- Parameters
module (objax.module.Module) – Objax module to be converted to Tensorflow tf.Module.
- class objax.util.Renamer(rules, chain=None)[source]¶
Helper class for renaming string contents.
- Parameters
rules (Union[Dict[str, str], Sequence[Tuple[Pattern[str], str]], Callable[[str], str]]) –
chain (Optional[Renamer]) –
- __init__(rules, chain=None)[source]¶
Create a renamer object.
- Parameters
rules (Union[Dict[str, str], Sequence[Tuple[Pattern[str], str]], Callable[[str], str]]) – the replacement mapping.
chain (Optional[objax.util.util.Renamer]) – optionally, another renamer to call after this one completes.
- objax.util.args_indexes(f, args)[source]¶
Returns the indexes of variable names of a function.
- Parameters
f (Callable) –
args (Iterable[str]) –
- Return type
Iterable[int]
- objax.util.find_used_variables(fn)[source]¶
Finds all Objax variables which are used by a given callable.
- Parameters
fn (Callable) – input function or callable.
- Returns
Variable collection with all variables used by input function.
- Return type
objax.util.image¶
|
Converts an array in (N,H,W,C) format to (N,C,H,W) format. |
|
Converts an array in (N,C,H,W) format to (N,H,W,C) format. |
Map a float image in [1/256-1, 1-1/256] to uint8 {0, 1, ..., 255}. |
|
Map an uint8 image in {0, 1, ..., 255} to float interval [1/256-1, 1-1/256]. |
|
|
Converts numpy array in (C,H,W) format into PNG format. |
- objax.util.image.from_file(file)[source]¶
Read an image from a file, convert it RGB and return it as an array.
- Parameters
file (Union[str, IO[BinaryIO]]) – filename or python file handle of the input file.
- Returns
3D numpy array (C, H, W) normalized with normalize_to_unit_float.
- Return type
numpy.ndarray
- objax.util.image.image_grid(image)[source]¶
Rearrange array of images (nh, hw, c, h, w) into image grid in a single image (c, nh * h, nh * w).
- Parameters
image (numpy.ndarray) –
- Return type
numpy.ndarray
- objax.util.image.nchw(x)[source]¶
Converts an array in (N,H,W,C) format to (N,C,H,W) format.
- Parameters
x (Union[numpy.ndarray, jax._src.numpy.lax_numpy.ndarray, jaxlib.xla_extension.DeviceArrayBase, jaxlib.xla_extension.pmap_lib.ShardedDeviceArrayBase]) –
- Return type
Union[numpy.ndarray, jax._src.numpy.lax_numpy.ndarray, jaxlib.xla_extension.DeviceArrayBase, jaxlib.xla_extension.pmap_lib.ShardedDeviceArrayBase]
- objax.util.image.nhwc(x)[source]¶
Converts an array in (N,C,H,W) format to (N,H,W,C) format.
- Parameters
x (Union[numpy.ndarray, jax._src.numpy.lax_numpy.ndarray, jaxlib.xla_extension.DeviceArrayBase, jaxlib.xla_extension.pmap_lib.ShardedDeviceArrayBase]) –
- Return type
Union[numpy.ndarray, jax._src.numpy.lax_numpy.ndarray, jaxlib.xla_extension.DeviceArrayBase, jaxlib.xla_extension.pmap_lib.ShardedDeviceArrayBase]
- objax.util.image.normalize_to_uint8(x)[source]¶
Map a float image in [1/256-1, 1-1/256] to uint8 {0, 1, …, 255}.
- Parameters
x (Union[numpy.ndarray, jax._src.numpy.lax_numpy.ndarray, jaxlib.xla_extension.DeviceArrayBase, jaxlib.xla_extension.pmap_lib.ShardedDeviceArrayBase]) –
- Return type
Union[numpy.ndarray, jax._src.numpy.lax_numpy.ndarray, jaxlib.xla_extension.DeviceArrayBase, jaxlib.xla_extension.pmap_lib.ShardedDeviceArrayBase]
- objax.util.image.normalize_to_unit_float(x)[source]¶
Map an uint8 image in {0, 1, …, 255} to float interval [1/256-1, 1-1/256].
- Parameters
x (Union[numpy.ndarray, jax._src.numpy.lax_numpy.ndarray, jaxlib.xla_extension.DeviceArrayBase, jaxlib.xla_extension.pmap_lib.ShardedDeviceArrayBase]) –
- Return type
Union[numpy.ndarray, jax._src.numpy.lax_numpy.ndarray, jaxlib.xla_extension.DeviceArrayBase, jaxlib.xla_extension.pmap_lib.ShardedDeviceArrayBase]