ethix commited on
Commit
76aa01e
·
1 Parent(s): 12fe8c7

fix: use num_labels=1 instead of num_classes=1

Browse files

num_classes=1 maps to num_labels=2 internally in ViTConfig,
creating [2,384] classifier that mismatches the safetensors.
num_labels=1 produces [1,384] — correct for single-class sigmoid.

Files changed (2) hide show
  1. README.md +2 -2
  2. config.json +1 -1
README.md CHANGED
@@ -38,7 +38,7 @@ The `model.safetensors` has been regenerated from the correct training checkpoin
38
  | Wrong `model.safetensors` | Weights from different model (intermediate_size=3072, wrong classifier) | Regenerated from `pretrained_weights/model_v11_ViT_384_base_ckpt.pt` |
39
  | `num_attention_heads: 12` | **Silently wrong** — attention sliced 12×32d instead of 6×64d | `6` |
40
  | Preprocessor `size` | Squashed non-square images or no center-crop | `shortest_edge: 440` + `do_center_crop` |
41
- | `num_classes: 2` / missing `id2label` | Wrong output format for single-class classifier | `1` (sigmoid output) |
42
 
43
  ### ⚠️ Breaking change for older transformers versions
44
 
@@ -50,7 +50,7 @@ This model now requires `transformers >= 5.4.0` for correct image preprocessing.
50
  import json
51
  with open("path/to/config.json") as f:
52
  cfg = json.load(f)
53
- assert cfg["num_classes"] == 1, "Still broken — re-download the model"
54
  assert cfg["num_attention_heads"] == 6, "Still broken — re-download the model"
55
  assert cfg["intermediate_size"] == 1536, "Still broken — re-download the model"
56
  ```
 
38
  | Wrong `model.safetensors` | Weights from different model (intermediate_size=3072, wrong classifier) | Regenerated from `pretrained_weights/model_v11_ViT_384_base_ckpt.pt` |
39
  | `num_attention_heads: 12` | **Silently wrong** — attention sliced 12×32d instead of 6×64d | `6` |
40
  | Preprocessor `size` | Squashed non-square images or no center-crop | `shortest_edge: 440` + `do_center_crop` |
41
+ | `num_classes: 2` / no `num_labels` | Wrong output format for single-class classifier — `num_classes=1` maps to 2 labels internally | `num_labels: 1` (sigmoid output) |
42
 
43
  ### ⚠️ Breaking change for older transformers versions
44
 
 
50
  import json
51
  with open("path/to/config.json") as f:
52
  cfg = json.load(f)
53
+ assert cfg["num_labels"] == 1, "Still broken — re-download the model"
54
  assert cfg["num_attention_heads"] == 6, "Still broken — re-download the model"
55
  assert cfg["intermediate_size"] == 1536, "Still broken — re-download the model"
56
  ```
config.json CHANGED
@@ -14,7 +14,7 @@
14
  "model_type": "vit",
15
  "num_attention_heads": 6,
16
  "num_channels": 3,
17
- "num_classes": 1,
18
  "num_hidden_layers": 12,
19
  "patch_size": 16,
20
  "qkv_bias": true,
 
14
  "model_type": "vit",
15
  "num_attention_heads": 6,
16
  "num_channels": 3,
17
+ "num_labels": 1,
18
  "num_hidden_layers": 12,
19
  "patch_size": 16,
20
  "qkv_bias": true,