Python & Pytorch

Utilities: Resizing and scaling images in python. And a filename-insensitive data loader.

I recently wrote this utility... a mere function, really, to resize and scale a python image at the center. This way, I don't have to worry about how my images are being fed into an AI pipeline, if they all get scaled and cropped the same.

Additionally, while previously I used bash to rename files in a folder to sequential names such as 1.jpg , the current implementation ignores filenames, which saves me time when massaging the data.

Pytorch cuda tries to allocate memory but it is not available

If you see an error similar to this one:

RuntimeError: CUDA out of memory. Tried to allocate 11.88 MiB (GPU 4; 15.75 GiB total capacity; 10.50 GiB already allocated; 1.88 MiB free; 3.03 GiB cached)

then, try reducing the batch size.

    train_loader = DataLoader(
        train_dataset,
        shuffle=False,
        pin_memory=False,
        batch_size=2, # was: 16
        num_workers=12,
    )