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/Segmentation/focalLoss.py from AndreCosta/resnet-unet-segmentation: direct link, hf CLI and curl.
- Browser
- Download file 441 Bytes
-
https://huggingface.co/AndreCosta/resnet-unet-segmentation/resolve/main/scripts/Segmentation/focalLoss.py
- Command line
-
hf download hf://AndreCosta/resnet-unet-segmentation/scripts/Segmentation/focalLoss.py
-
curl -L -o focalLoss.py https://huggingface.co/AndreCosta/resnet-unet-segmentation/resolve/main/scripts/Segmentation/focalLoss.py
441 Bytes
| import torch | |
| import torch.nn as nn | |
| class FocalLoss(nn.Module): | |
| def __init__(self, gamma=2.0, weight=None): | |
| super(FocalLoss, self).__init__() | |
| self.gamma = gamma | |
| self.ce = nn.CrossEntropyLoss(weight=weight) | |
| def forward(self, logits, targets): | |
| logits = logits.float() | |
| ce_loss = self.ce(logits, targets) | |
| pt = torch.exp(-ce_loss) | |
| return ((1 - pt) ** self.gamma * ce_loss).mean() | |