Util

Miscellaneous util code.

Memory utils


source

MemoryCleaner

 MemoryCleaner ()

CLass with static methods to clean (gpu) memory.

Python utils


source

virtual

 virtual (f:<built-infunctioncallable>)

Decorator to enfore subclass method implementations and raises error at method calls.

class A():
    def p1(self, x): print("A p1", x)
    
    @virtual
    def p2(self, x): pass
 
class B(A):
    def p3(self, x): print("B p2", x)
    
b = B()
b.p1(1)
try:
    b.p2(1)
except BaseException as e:
    print("Exception that would be raised: ", e)
A p1 1
Exception that would be raised:  Virtual method p2 needs to be implemented by subclass B.

Torch utils


source

DataLoaders

 DataLoaders (*dls:list[torch.utils.data.dataloader.DataLoader])

Combines train and valid DataLoader.


source

infer_torch_device

 infer_torch_device ()
infer_torch_device()
[INFO]: Cuda device has a capability of 8.6 (>= 8), allowing tf32 matmul.
device(type='cuda')

source

number_of_paramters

 number_of_paramters (model:torch.nn.modules.module.Module)

source

scale_tensor

 scale_tensor (t:torch.Tensor)

[-1,1] to [0,1]


source

normalize_tensor

 normalize_tensor (t:torch.Tensor)

[0,1] to [-1,1]

Plot utils


source

saveSvg

 saveSvg (filename)

source

savePng

 savePng (filename)

source

savePdf

 savePdf (filename)

source

plot_image_grid

 plot_image_grid (imgs:Union[list,<built-infunctionarray>,torch.Tensor],
                  labels:list=None, labels_fs='medium', figsize=(16, 4),
                  cols=8, cmap='Greys', show_colorbar=False,
                  **imshow_kwargs)
n = 6
plot_image_grid(torch.randn((n,28,28,1)), [f"label {i}" for i in range(n)])


source

latents_to_pil

 latents_to_pil (latents:torch.Tensor, channels=None)
Back to top