torch_mimicry.utils

Contents

Common Utilities

Script for common utility functions.

load_from_json(json_file)[source]

Loads a JSON file as a dictionary and return it.

Parameters:json_file (str) – Input JSON file to read.
Returns:Dictionary loaded from the JSON file.
Return type:dict
load_images(n=1, size=32)[source]

Load n image tensors with some fake labels.

Parameters:
  • n (int) – Number of random images to load.
  • size (int) – Spatial size of random image.
Returns:

Random images of shape (n, 3, size, size) and 0-valued labels.

Return type:

Tensor

save_tensor_image(x, output_file)[source]

Saves an input image tensor as some numpy array, useful for tests.

Parameters:
  • x (Tensor) – A 3D tensor image of shape (3, H, W).
  • output_file (str) – The output image file to save the tensor.
Returns:

None

write_to_json(dict_to_write, output_file)[source]

Outputs a given dictionary as a JSON file with indents.

Parameters:
  • dict_to_write (dict) – Input dictionary to output.
  • output_file (str) – File path to write the dictionary.
Returns:

None