Spaces:
Runtime error
Runtime error
Download utils.py from Sanket17/omniparser: direct link, hf CLI and curl.
- Browser
- Download file 493 Bytes
-
https://huggingface.co/spaces/Sanket17/omniparser/resolve/main/utils.py
- Command line
-
hf download hf://spaces/Sanket17/omniparser/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/Sanket17/omniparser/resolve/main/utils.py
493 Bytes
| from PIL import Image | |
| import torch | |
| def preprocess_image(image: Image.Image, size: int = 224): | |
| """ | |
| Resize and preprocess the image for the model. | |
| Args: | |
| image (PIL.Image): The input image. | |
| size (int): Target size for resizing. | |
| Returns: | |
| torch.Tensor: Preprocessed image tensor. | |
| """ | |
| image = image.resize((size, size)) # Resize to 224x224 | |
| image_tensor = torch.tensor(image).permute(2, 0, 1).unsqueeze(0).float() / 255.0 | |
| return image_tensor | |