Spaces:
Running
Running
added softmax temperature for better uncertainty calibration
Browse files- app/model.py +2 -1
app/model.py
CHANGED
|
@@ -10,6 +10,7 @@ from transformers import AutoImageProcessor, AutoModelForImageClassification
|
|
| 10 |
HF_NAME = "microsoft/swinv2-base-patch4-window16-256"
|
| 11 |
WEIGHTS_PATH = Path(__file__).parent.parent / "model.safetensors"
|
| 12 |
NUM_LABELS = 2
|
|
|
|
| 13 |
|
| 14 |
_device = torch.device("cpu")
|
| 15 |
_processor = None
|
|
@@ -72,5 +73,5 @@ def predict_image(image: Image.Image) -> float:
|
|
| 72 |
image = image.convert("RGB")
|
| 73 |
inputs = processor(images=image, return_tensors="pt").to(_device)
|
| 74 |
logits = model(**inputs).logits
|
| 75 |
-
probs = torch.softmax(logits, dim=-1)
|
| 76 |
return float(probs[0, 1].item())
|
|
|
|
| 10 |
HF_NAME = "microsoft/swinv2-base-patch4-window16-256"
|
| 11 |
WEIGHTS_PATH = Path(__file__).parent.parent / "model.safetensors"
|
| 12 |
NUM_LABELS = 2
|
| 13 |
+
SOFTMAX_TEMPERATURE = 1.5
|
| 14 |
|
| 15 |
_device = torch.device("cpu")
|
| 16 |
_processor = None
|
|
|
|
| 73 |
image = image.convert("RGB")
|
| 74 |
inputs = processor(images=image, return_tensors="pt").to(_device)
|
| 75 |
logits = model(**inputs).logits
|
| 76 |
+
probs = torch.softmax(logits / SOFTMAX_TEMPERATURE, dim=-1)
|
| 77 |
return float(probs[0, 1].item())
|