Image Segmentation
BiRefNet
Safetensors
background-removal
mask-generation
Dichotomous Image Segmentation
Camouflaged Object Detection
pytorch_model_hub_mixin
model_hub_mixin
custom_code
Instructions to use ZhengPeng7/BiRefNet-COD with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- BiRefNet
How to use ZhengPeng7/BiRefNet-COD with BiRefNet:
# Option 1: use with transformers from transformers import AutoModelForImageSegmentation birefnet = AutoModelForImageSegmentation.from_pretrained("ZhengPeng7/BiRefNet-COD", trust_remote_code=True)# Option 2: use with BiRefNet # Install from https://github.com/ZhengPeng7/BiRefNet from models.birefnet import BiRefNet model = BiRefNet.from_pretrained("ZhengPeng7/BiRefNet-COD") - Notebooks
- Google Colab
- Kaggle
Dtype adaptability between FP32 and FP16 in inference.
Browse files- birefnet.py +1 -1
birefnet.py
CHANGED
|
@@ -992,7 +992,7 @@ class BasicLayer(nn.Module):
|
|
| 992 |
mask_windows = window_partition(img_mask, self.window_size) # nW, window_size, window_size, 1
|
| 993 |
mask_windows = mask_windows.view(-1, self.window_size * self.window_size)
|
| 994 |
attn_mask = mask_windows.unsqueeze(1) - mask_windows.unsqueeze(2)
|
| 995 |
-
attn_mask = attn_mask.masked_fill(attn_mask != 0, float(-100.0)).masked_fill(attn_mask == 0, float(0.0))
|
| 996 |
|
| 997 |
for blk in self.blocks:
|
| 998 |
blk.H, blk.W = H, W
|
|
|
|
| 992 |
mask_windows = window_partition(img_mask, self.window_size) # nW, window_size, window_size, 1
|
| 993 |
mask_windows = mask_windows.view(-1, self.window_size * self.window_size)
|
| 994 |
attn_mask = mask_windows.unsqueeze(1) - mask_windows.unsqueeze(2)
|
| 995 |
+
attn_mask = attn_mask.masked_fill(attn_mask != 0, float(-100.0)).masked_fill(attn_mask == 0, float(0.0)).to(x.dtype)
|
| 996 |
|
| 997 |
for blk in self.blocks:
|
| 998 |
blk.H, blk.W = H, W
|