objax.util package

objax.util

EasyDict(*args, **kwargs)

Custom dictionary that allows to access dict values as attributes.

args_indexes(f, args)

Returns the indexes of variable names of a function.

dummy_context_mgr()

Empty Context Manager.

ilog2(x)

Integer log2.

positional_args_names(f)

Returns the ordered names of the positional arguments of a function.

to_tuple(v, n)

Converts input to tuple.

class objax.util.EasyDict(*args, **kwargs)[source]

Custom dictionary that allows to access dict values as attributes.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

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
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.dummy_context_mgr()[source]

Empty Context Manager.

objax.util.ilog2(x)[source]

Integer log2.

Parameters

x (float) –

objax.util.positional_args_names(f)[source]

Returns the ordered names of the positional arguments of a function.

Parameters

f (Callable) –

Return type

List[str]

objax.util.to_tuple(v, n)[source]

Converts input to tuple.

Parameters
  • v (Union[Tuple[numbers.Number, ..], numbers.Number, Iterable]) –

  • n (int) –

objax.util.image

nchw(x)

Converts an array in (N,H,W,C) format to (N,C,H,W) format.

nhwc(x)

Converts an array in (N,C,H,W) format to (N,H,W,C) format.

normalize_to_uint8(x)

Map a float image in [1/256-1, 1-1/256] to uint8 {0, 1, …, 255}.

normalize_to_unit_float(x)

Map an uint8 image in {0, 1, …, 255} to float interval [1/256-1, 1-1/256].

to_png(x)

Converts numpy array in (C,H,W) format into PNG format.

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.numpy.lax_numpy.ndarray, jax.interpreters.xla.DeviceArray, jax.interpreters.pxla.ShardedDeviceArray]) –

Return type

Union[numpy.ndarray, jax.numpy.lax_numpy.ndarray, jax.interpreters.xla.DeviceArray, jax.interpreters.pxla.ShardedDeviceArray]

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.numpy.lax_numpy.ndarray, jax.interpreters.xla.DeviceArray, jax.interpreters.pxla.ShardedDeviceArray]) –

Return type

Union[numpy.ndarray, jax.numpy.lax_numpy.ndarray, jax.interpreters.xla.DeviceArray, jax.interpreters.pxla.ShardedDeviceArray]

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.numpy.lax_numpy.ndarray, jax.interpreters.xla.DeviceArray, jax.interpreters.pxla.ShardedDeviceArray]) –

Return type

Union[numpy.ndarray, jax.numpy.lax_numpy.ndarray, jax.interpreters.xla.DeviceArray, jax.interpreters.pxla.ShardedDeviceArray]

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.numpy.lax_numpy.ndarray, jax.interpreters.xla.DeviceArray, jax.interpreters.pxla.ShardedDeviceArray]) –

Return type

Union[numpy.ndarray, jax.numpy.lax_numpy.ndarray, jax.interpreters.xla.DeviceArray, jax.interpreters.pxla.ShardedDeviceArray]

objax.util.image.to_png(x)[source]

Converts numpy array in (C,H,W) format into PNG format.

Parameters

x (numpy.ndarray) –

Return type

bytes