Image Classification
Transformers
Safetensors
nula
computer-vision
cnn
cifar10
adversarial-robustness
stress-test
downsampling
anti-aliasing
custom_code
Instructions to use MamaPearl/nula-cifar10-robust-v0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MamaPearl/nula-cifar10-robust-v0 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="MamaPearl/nula-cifar10-robust-v0", trust_remote_code=True) pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoModelForImageClassification model = AutoModelForImageClassification.from_pretrained("MamaPearl/nula-cifar10-robust-v0", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update augmentations.py
Browse files- augmentations.py +4 -0
augmentations.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
import torch as pt
|
| 2 |
import torch.nn.functional as F
|
| 3 |
import numbers
|
|
|
|
| 4 |
def resize_down_up(x, scale=0.5, mode="bilinear"):
|
|
|
|
| 5 |
if isinstance(scale, pt.Tensor):
|
| 6 |
scale = scale.item()
|
| 7 |
_val_invars(x, scale=scale, mode=mode, type="resize")
|
|
@@ -16,6 +18,7 @@ def resize_down_up(x, scale=0.5, mode="bilinear"):
|
|
| 16 |
return F.interpolate(x_down, size=(H,W), mode=mode, **kwargs)
|
| 17 |
|
| 18 |
def _val_invars(x, **kwargs):
|
|
|
|
| 19 |
if x.ndim != 4:
|
| 20 |
raise ValueError(f"x needs shape (B,C,H,W), got {x.shape}")
|
| 21 |
op_type = kwargs.get("type")
|
|
@@ -55,6 +58,7 @@ def checkerboard_alias_attack(
|
|
| 55 |
x: pt.Tensor,
|
| 56 |
epsilon: float=0.5,
|
| 57 |
):
|
|
|
|
| 58 |
_val_invars(x, epsilon=epsilon, type="attack")
|
| 59 |
B, C, H, W = x.shape
|
| 60 |
device = x.device
|
|
|
|
| 1 |
import torch as pt
|
| 2 |
import torch.nn.functional as F
|
| 3 |
import numbers
|
| 4 |
+
|
| 5 |
def resize_down_up(x, scale=0.5, mode="bilinear"):
|
| 6 |
+
# shrinks image then blows it back up to see what info was lost
|
| 7 |
if isinstance(scale, pt.Tensor):
|
| 8 |
scale = scale.item()
|
| 9 |
_val_invars(x, scale=scale, mode=mode, type="resize")
|
|
|
|
| 18 |
return F.interpolate(x_down, size=(H,W), mode=mode, **kwargs)
|
| 19 |
|
| 20 |
def _val_invars(x, **kwargs):
|
| 21 |
+
# validate invariants
|
| 22 |
if x.ndim != 4:
|
| 23 |
raise ValueError(f"x needs shape (B,C,H,W), got {x.shape}")
|
| 24 |
op_type = kwargs.get("type")
|
|
|
|
| 58 |
x: pt.Tensor,
|
| 59 |
epsilon: float=0.5,
|
| 60 |
):
|
| 61 |
+
# injects high-frequency noise that mimics sampling artifacts
|
| 62 |
_val_invars(x, epsilon=epsilon, type="attack")
|
| 63 |
B, C, H, W = x.shape
|
| 64 |
device = x.device
|