Skip to content

Instantly share code, notes, and snippets.

import os
import warnings
import PIL
from PIL import Image
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
import torch
import argparse
import numpy as np
@tyuvraj
tyuvraj / img_aug_seg.py
Last active September 12, 2024 08:03
random crop and resize while preserving aspect ratio
import numpy as np
import random
def get_resize_shape(H, W, length=720):
if H > W and H > length:
new_H, new_W = length, int(W / H * length)
elif W > H and W > length:
new_H, new_W = int(H / W * length), length
else:
new_H, new_W = H, W