Instructions to use kd13/Modern-SqueezeNet with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kd13/Modern-SqueezeNet with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="kd13/Modern-SqueezeNet", 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("kd13/Modern-SqueezeNet", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update modeling_squeezenet.py
Browse files- modeling_squeezenet.py +2 -10
modeling_squeezenet.py
CHANGED
|
@@ -3,7 +3,6 @@ import torch.nn as nn
|
|
| 3 |
import torch.nn.functional as F
|
| 4 |
from transformers import PreTrainedModel
|
| 5 |
from transformers.modeling_outputs import ImageClassifierOutput
|
| 6 |
-
|
| 7 |
try:
|
| 8 |
from .configuration_squeezenet import SqueezeNetConfig
|
| 9 |
except ImportError:
|
|
@@ -81,7 +80,6 @@ class SqueezeNetForImageClassification(PreTrainedModel):
|
|
| 81 |
|
| 82 |
self.gap = nn.AdaptiveAvgPool2d((1, 1))
|
| 83 |
|
| 84 |
-
# Important: Automatically initializes weights if needed, required by Transformers
|
| 85 |
self.post_init()
|
| 86 |
|
| 87 |
def _init_weights(self, module):
|
|
@@ -93,17 +91,11 @@ class SqueezeNetForImageClassification(PreTrainedModel):
|
|
| 93 |
nn.init.ones_(module.weight)
|
| 94 |
nn.init.zeros_(module.bias)
|
| 95 |
|
| 96 |
-
# Override for the classifier
|
| 97 |
if module == self.conv10:
|
| 98 |
nn.init.normal_(module.weight, mean=0.0, std=0.001)
|
| 99 |
nn.init.zeros_(module.bias)
|
| 100 |
|
| 101 |
-
def forward(
|
| 102 |
-
self,
|
| 103 |
-
pixel_values: torch.Tensor,
|
| 104 |
-
labels: torch.Tensor | None = None,
|
| 105 |
-
return_dict: bool | None = None
|
| 106 |
-
):
|
| 107 |
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 108 |
|
| 109 |
x = self.pool1(self.act1(self.norm1(self.conv1(pixel_values))))
|
|
@@ -136,4 +128,4 @@ class SqueezeNetForImageClassification(PreTrainedModel):
|
|
| 136 |
return ImageClassifierOutput(
|
| 137 |
loss=loss,
|
| 138 |
logits=logits,
|
| 139 |
-
)
|
|
|
|
| 3 |
import torch.nn.functional as F
|
| 4 |
from transformers import PreTrainedModel
|
| 5 |
from transformers.modeling_outputs import ImageClassifierOutput
|
|
|
|
| 6 |
try:
|
| 7 |
from .configuration_squeezenet import SqueezeNetConfig
|
| 8 |
except ImportError:
|
|
|
|
| 80 |
|
| 81 |
self.gap = nn.AdaptiveAvgPool2d((1, 1))
|
| 82 |
|
|
|
|
| 83 |
self.post_init()
|
| 84 |
|
| 85 |
def _init_weights(self, module):
|
|
|
|
| 91 |
nn.init.ones_(module.weight)
|
| 92 |
nn.init.zeros_(module.bias)
|
| 93 |
|
|
|
|
| 94 |
if module == self.conv10:
|
| 95 |
nn.init.normal_(module.weight, mean=0.0, std=0.001)
|
| 96 |
nn.init.zeros_(module.bias)
|
| 97 |
|
| 98 |
+
def forward(self, pixel_values: torch.Tensor, labels: torch.Tensor | None = None, return_dict: bool | None = None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 100 |
|
| 101 |
x = self.pool1(self.act1(self.norm1(self.conv1(pixel_values))))
|
|
|
|
| 128 |
return ImageClassifierOutput(
|
| 129 |
loss=loss,
|
| 130 |
logits=logits,
|
| 131 |
+
)
|