broccoli-ml 1.1.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: broccoli-ml
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: Some useful Pytorch models, circa 2025
5
5
  License: MIT
6
6
  Author: Nicholas Bailey
@@ -53,12 +53,20 @@ class ClassificationHead(nn.Module):
53
53
  A general classification head for a ViT
54
54
  """
55
55
 
56
- def __init__(self, d_model, linear_module, n_classes, batch_norm=True):
56
+ def __init__(
57
+ self,
58
+ d_model,
59
+ n_classes,
60
+ linear_module=nn.Linear,
61
+ logit_projection_layer=nn.Linear,
62
+ batch_norm_logits=True,
63
+ ):
57
64
  super().__init__()
58
65
  self.d_model = d_model
59
66
  self.summarize = GetCLSToken()
60
- self.projection = linear_module(d_model, n_classes)
61
- if batch_norm:
67
+ self.projection = logit_projection_layer(d_model, n_classes)
68
+
69
+ if batch_norm_logits:
62
70
  self.batch_norm = nn.BatchNorm1d(n_classes, affine=False)
63
71
  else:
64
72
  self.batch_norm = nn.Identity()
@@ -83,7 +91,7 @@ class SequencePoolClassificationHead(ClassificationHead):
83
91
  """
84
92
 
85
93
  def __init__(self, d_model, linear_module, out_dim, batch_norm=True):
86
- super().__init__(d_model, linear_module, out_dim, batch_norm=batch_norm)
94
+ super().__init__(d_model, linear_module, out_dim, batch_norm_logits=batch_norm)
87
95
  self.summarize = SequencePool(d_model, linear_module)
88
96
  # Rebuild the classification process with the correct summary module:
89
97
  self.classification_process = nn.Sequential(
@@ -411,9 +419,10 @@ class ViT(nn.Module):
411
419
  transformer_mlp_dropout=0.0,
412
420
  transformer_msa_dropout=0.1,
413
421
  transformer_stochastic_depth=0.1,
414
- batch_norm_outputs=True,
415
- linear_module=SpectralNormLinear,
416
422
  head=SequencePoolClassificationHead,
423
+ batch_norm_logits=True,
424
+ logit_projection_layer=nn.Linear,
425
+ linear_module=nn.Linear,
417
426
  ):
418
427
 
419
428
  super().__init__()
@@ -480,9 +489,10 @@ class ViT(nn.Module):
480
489
 
481
490
  self.pool = head(
482
491
  transformer_embedding_size,
483
- linear_module,
484
492
  image_classes,
485
- batch_norm=batch_norm_outputs,
493
+ linear_module=linear_module,
494
+ logit_projection_layer=logit_projection_layer,
495
+ batch_norm=batch_norm_logits,
486
496
  )
487
497
 
488
498
  @property
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "broccoli-ml"
3
- version = "1.1.0"
3
+ version = "1.2.0"
4
4
  description = "Some useful Pytorch models, circa 2025"
5
5
  authors = [
6
6
  {name = "Nicholas Bailey"}
File without changes
File without changes
File without changes