Instructions to use AndreCosta/resnet-unet-segmentation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AndreCosta/resnet-unet-segmentation with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-segmentation", model="AndreCosta/resnet-unet-segmentation")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("AndreCosta/resnet-unet-segmentation", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download scripts/Dataset/dataAugmentation.py from AndreCosta/resnet-unet-segmentation: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/AndreCosta/resnet-unet-segmentation/resolve/main/scripts/Dataset/dataAugmentation.py
- Command line
-
hf download hf://AndreCosta/resnet-unet-segmentation/scripts/Dataset/dataAugmentation.py
-
curl -L -o dataAugmentation.py https://huggingface.co/AndreCosta/resnet-unet-segmentation/resolve/main/scripts/Dataset/dataAugmentation.py
1.39 kB
| import os | |
| import cv2 | |
| import numpy as np | |
| from PIL import Image | |
| import albumentations as A | |
| import scripts.config as config | |
| input_img_dir = config.images | |
| out_img_dir = config.images #+ "/images_aug" | |
| input_mask_dir = config.masks | |
| out_mask_dir = config.masks #+ "/masks_aug" | |
| print('Starting...') | |
| os.makedirs(out_img_dir, exist_ok=True) | |
| os.makedirs(out_mask_dir, exist_ok=True) | |
| transformations = [ | |
| ("flip", A.HorizontalFlip(p=1.0)), | |
| ("rot15", A.Rotate(limit=15, p=1.0)), | |
| ("contrast", A.RandomBrightnessContrast(p=1.0)), | |
| ] | |
| for fname in os.listdir(input_img_dir): | |
| if not fname.endswith(".jpg"): continue | |
| base = fname.replace(".jpg", "") | |
| img_path = os.path.join(input_img_dir, fname) | |
| mask_path = os.path.join(input_mask_dir, base + "_mask.png") | |
| img = np.array(Image.open(img_path).convert("L")) | |
| mask = np.array(Image.open(mask_path).convert("L")) | |
| mask = (mask > 127).astype('uint8') | |
| for name, tf in transformations: | |
| aug = A.Compose([tf]) | |
| augmented = aug(image=img, mask=mask) | |
| img_aug = augmented['image'] | |
| mask_aug = augmented['mask'] | |
| img_out = os.path.join(out_img_dir, f"{base}_aug_{name}.jpg") | |
| mask_out = os.path.join(out_mask_dir, f"{base}_aug_{name}_mask.png") | |
| cv2.imwrite(img_out, img_aug) | |
| cv2.imwrite(mask_out, mask_aug * 255) | |
| print('Completed...') | |