Instructions to use kd13/Modern-MobileNet with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kd13/Modern-MobileNet with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="kd13/Modern-MobileNet", trust_remote_code=True) pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForImageClassification model = AutoModelForImageClassification.from_pretrained("kd13/Modern-MobileNet", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update modeling_mobilenet.py
Browse files- modeling_mobilenet.py +2 -9
modeling_mobilenet.py
CHANGED
|
@@ -58,14 +58,12 @@ class MobileNetV1ForImageClassification(PreTrainedModel):
|
|
| 58 |
super().__init__(config)
|
| 59 |
self.num_labels = config.num_classes
|
| 60 |
|
| 61 |
-
# Stem
|
| 62 |
self.stem = nn.Sequential(
|
| 63 |
nn.Conv2d(3, 32, kernel_size=3, stride=2, padding=1, bias=False),
|
| 64 |
FP32LayerNorm2d(32),
|
| 65 |
nn.SiLU(inplace=True)
|
| 66 |
)
|
| 67 |
|
| 68 |
-
# Blocks
|
| 69 |
self.blocks = nn.Sequential(
|
| 70 |
DepthwiseSeparableConv(32, 64, stride=1, dropout=config.block_dropout),
|
| 71 |
DepthwiseSeparableConv(64, 128, stride=2, dropout=config.block_dropout),
|
|
@@ -101,12 +99,7 @@ class MobileNetV1ForImageClassification(PreTrainedModel):
|
|
| 101 |
if module.bias is not None:
|
| 102 |
nn.init.zeros_(module.bias)
|
| 103 |
|
| 104 |
-
def forward(
|
| 105 |
-
self,
|
| 106 |
-
pixel_values=None,
|
| 107 |
-
labels=None,
|
| 108 |
-
return_dict=None,
|
| 109 |
-
):
|
| 110 |
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 111 |
|
| 112 |
x = self.stem(pixel_values)
|
|
@@ -128,4 +121,4 @@ class MobileNetV1ForImageClassification(PreTrainedModel):
|
|
| 128 |
return ImageClassifierOutput(
|
| 129 |
loss=loss,
|
| 130 |
logits=logits,
|
| 131 |
-
)
|
|
|
|
| 58 |
super().__init__(config)
|
| 59 |
self.num_labels = config.num_classes
|
| 60 |
|
|
|
|
| 61 |
self.stem = nn.Sequential(
|
| 62 |
nn.Conv2d(3, 32, kernel_size=3, stride=2, padding=1, bias=False),
|
| 63 |
FP32LayerNorm2d(32),
|
| 64 |
nn.SiLU(inplace=True)
|
| 65 |
)
|
| 66 |
|
|
|
|
| 67 |
self.blocks = nn.Sequential(
|
| 68 |
DepthwiseSeparableConv(32, 64, stride=1, dropout=config.block_dropout),
|
| 69 |
DepthwiseSeparableConv(64, 128, stride=2, dropout=config.block_dropout),
|
|
|
|
| 99 |
if module.bias is not None:
|
| 100 |
nn.init.zeros_(module.bias)
|
| 101 |
|
| 102 |
+
def forward(self, pixel_values=None, labels=None, return_dict=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 104 |
|
| 105 |
x = self.stem(pixel_values)
|
|
|
|
| 121 |
return ImageClassifierOutput(
|
| 122 |
loss=loss,
|
| 123 |
logits=logits,
|
| 124 |
+
)
|