# pystiche¶

pystiche.home()

Local directory to save downloaded images and guides. Defaults to ~/.cache/pystiche but can be overwritten with the PYSTICHE_HOME environment variable.

Return type

str

## Objects¶

class pystiche.ComplexObject

Object with a complex representation. See pystiche.misc.build_complex_obj_repr() for details.

_named_children()
Yields

Internal named children.

Note

If subclassed, this method should yield the named children of the superclass alongside yielding the new named children.

Return type
_properties()
Return type
Returns

Internal properties.

Note

If subclassed, this method should integrate the new properties in the properties of the superclass.

extra_named_children()
Yields

Extra named children.

Return type
extra_properties()
Return type
Returns

Extra properties.

named_children()
Yields

Internal and extra named children.

Return type
properties()
Return type
Returns

Internal and extra properties.

class pystiche.LossDict(losses=())

Hierarchic dictionary of scalar torch.Tensor losses. Levels are seperated by "." in the names.

Parameters

losses (Sequence[Tuple[str, Union[Tensor, LossDict]]]) – Optional named losses.

__mul__(other)

Multiplies all entries with a scalar.

Parameters

other (SupportsFloat) – Scalar multiplier.

Return type

LossDict

__setitem__(name, loss)

Add a named loss to the entries.

Parameters
Raises

TypeError – If loss is torch.Tensor but isn’t scalar.

Return type

None

aggregate(max_depth)

Aggregate all entries up to a given maximum depth.

Parameters

max_depth (int) – If 0 returns sum of all entries as scalar torch.Tensor.

Return type
backward(*args, **kwargs)

Computes the gradient of all entries with respect to the graph leaves. See torch.Tensor.backward() for details.

Return type

None

item()
Return type

float

Returns

The sum of all entries as standard Python number.

total()
Return type

Tensor

Returns

Sum of all entries as scalar tensor.

class pystiche.Module(named_children=None, indexed_children=None)

torch.nn.Module with the enhanced representation options of pystiche.ComplexObject.

Parameters

Note

named_children and indexed_children are mutually exclusive parameters.

torch_repr()
Return type

str

Returns

Native torch representation.

## Math¶

pystiche.nonnegsqrt(x)

Safely calculates the square-root of a non-negative input


Note

This operation is useful in situations where the input tensor is strictly non-negative from a theoretical standpoint, but might be negative due to numerical instabilities.

Parameters

x (Tensor) – Input tensor.

Return type

Tensor

pystiche.gram_matrix(x, normalize=False)

Calculates the channel-wise Gram matrix of a batched input tensor.




Parameters


Return type

Tensor

Returns


pystiche.cosine_similarity(x1, x2, eps=1e-08, batched_input=None)

Calculates the cosine similarity between the samples of x1 and x2.

Parameters


• eps (float) – Small value to avoid zero division. Defaults to 1e-8.


Return type

Tensor

Returns
