Run this model with HF Jobs
Run Thastp/efficientnet_b0 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Thastp/efficientnet_b0. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Thastp/efficientnet_b0 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use Thastp/efficientnet_b0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Thastp/efficientnet_b0 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="Thastp/efficientnet_b0", 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 AutoImageProcessor, AutoModelForImageClassification processor = AutoImageProcessor.from_pretrained("Thastp/efficientnet_b0", trust_remote_code=True) model = AutoModelForImageClassification.from_pretrained("Thastp/efficientnet_b0", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload model
Browse filesFiles changed (3)
- config.json+2-3
- configuration_efficientnet.py+12-10
- modeling_efficientnet.py+125-51
1234567891011{"_name_or_path": "./efficientnet/temp","architectures": ["EfficientNetModelForImageClassification"],"auto_map": {"AutoConfig": "configuration_efficientnet.EfficientNetConfig","AutoModelForImageClassification": "modeling_efficientnet.EfficientNetModelForImageClassification"},"global_pool": "avg","model_name": "efficientnet_b0",12345678910{"architectures": ["EfficientNetModel"],"auto_map": {"AutoConfig": "configuration_efficientnet.EfficientNetConfig","AutoModel": "modeling_efficientnet.EfficientNetModel"},"global_pool": "avg","model_name": "efficientnet_b0",
1234568 unmodified lines1516171819202122232425262728293031321 unmodified line3435363738394041424 unmodified lines474849505152from transformers.configuration_utils import PretrainedConfigfrom optimum.exporters.onnx.model_configs import ViTOnnxConfigfrom typing import DictMODEL_NAMES = ['efficientnet_b0',8 unmodified lines'efficientnet_l2']class EfficientNetConfig(PretrainedConfig):model_type = 'efficientnet'def __init__(self,model_name: str = 'efficientnet_b0',pretrained: bool = False,num_classes: int = 1000,global_pool: str = 'avg',**kwargs):if model_name not in MODEL_NAMES:raise ValueError(f'`model_name` must be one of these: {MODEL_NAMES}, but got {model_name}')1 unmodified lineself.pretrained = pretrainedself.num_classes = num_classesself.global_pool = global_poolsuper().__init__(**kwargs)class EfficientNetOnnxConfig(ViTOnnxConfig):@propertydef outputs(self) -> Dict[str, Dict[int, str]]:4 unmodified linesreturn common_outputs__all__ = ['MODEL_NAMES','EfficientNetConfig',12345678 unmodified lines1617181920212223242526272829303132331 unmodified line3536373839404142434 unmodified lines48495051525354from typing import Dictfrom transformers.configuration_utils import PretrainedConfigfrom optimum.exporters.onnx.model_configs import ViTOnnxConfigMODEL_NAMES = ['efficientnet_b0',8 unmodified lines'efficientnet_l2']class EfficientNetConfig(PretrainedConfig):model_type = 'efficientnet'def __init__(self,model_name: str = 'efficientnet_b0',pretrained: bool = False,num_classes: int = 1000,global_pool: str = 'avg',**kwargs,):if model_name not in MODEL_NAMES:raise ValueError(f'`model_name` must be one of these: {MODEL_NAMES}, but got {model_name}')1 unmodified lineself.pretrained = pretrainedself.num_classes = num_classesself.global_pool = global_poolsuper().__init__(**kwargs)class EfficientNetOnnxConfig(ViTOnnxConfig):@propertydef outputs(self) -> Dict[str, Dict[int, str]]:4 unmodified linesreturn common_outputs__all__ = ['MODEL_NAMES','EfficientNetConfig',
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152from torch import nnfrom transformers import PreTrainedModelfrom transformers.modeling_outputs import BaseModelOutputWithPoolingAndNoAttention, ImageClassifierOutputWithNoAttentionfrom timm import create_modelfrom .configuration_efficientnet import EfficientNetConfigclass EfficientNetModel(PreTrainedModel):config_class = EfficientNetConfigdef __init__(self, config):super().__init__(config)self.config = configself.model = create_model(config.model_name,pretrained = config.pretrained,num_classes = config.num_classes,global_pool = config.global_pool)def forward(self, pixel_values):last_hidden_state = self.model.forward_features(pixel_values)return BaseModelOutputWithPoolingAndNoAttention(last_hidden_state = last_hidden_state)class EfficientNetModelForImageClassification(PreTrainedModel):config_class = EfficientNetConfigdef __init__(self, config):super().__init__(config)self.config = configself.model = create_model(config.model_name,pretrained = config.pretrained,num_classes = config.num_classes,global_pool = config.global_pool)def forward(self, pixel_values, labels=None):logits = self.model(pixel_values)loss = Noneif labels is not None:loss = nn.CrossEntropyLoss(logits, labels)return ImageClassifierOutputWithNoAttention(loss = loss,logits = logits)__all__ = ["EfficientNetModel","EfficientNetModelForImageClassification"]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126from torch import nn, Tensor, tensorfrom typing import Union, List, Optionalfrom transformers import PreTrainedModelfrom transformers.modeling_outputs import (BaseModelOutputWithPoolingAndNoAttention,ImageClassifierOutputWithNoAttention)from timm import create_modelfrom .configuration_efficientnet import EfficientNetConfigclass EfficientNetModel(PreTrainedModel):"""EfficientNet model wrapper using Hugging Face's PreTrainedModel.This class initializes an EfficientNet model from `timm` libraryand defines a forward method that extracts feature representations.Attributes----------config:Configuration object containing model parameters.model:Instantiated EfficientNet model."""config_class = EfficientNetConfigdef __init__(self, config):super().__init__(config)self.config = configself.model = create_model(config.model_name,pretrained = config.pretrained,num_classes = config.num_classes,global_pool = config.global_pool,)def forward(self, pixel_values: Tensor) -> BaseModelOutputWithPoolingAndNoAttention:"""Parameters----------pixel_values : torch.TensorInput tensor representing image pixel values.Returns-------BaseModelOutputWithPoolingAndNoAttentionObject containing the `last_hidden_state` and `pooled_output`."""last_hidden_state = self.model.forward_features(pixel_values)pooler_output = self.model.forward_head(last_hidden_state, pre_logits=True)return BaseModelOutputWithPoolingAndNoAttention(last_hidden_state = last_hidden_state,pooler_output=pooler_output)class EfficientNetModelForImageClassification(PreTrainedModel):"""EfficientNet model wrapper using Hugging Face's PreTrainedModel.This class initializes an EfficientNet model from `timm` libraryand defines a forward method that return logits.It supports training when labels are providedAttributes----------config :Configuration object containing model parameters.model :Instantiated EfficientNet model."""config_class = EfficientNetConfigdef __init__(self, config):super().__init__(config)self.config = configself.model = create_model(config.model_name,pretrained = config.pretrained,num_classes = config.num_classes,global_pool = config.global_pool,)def forward(self,pixel_values: Tensor,labels: Optional[Union[List[int], Tensor]] = None) -> ImageClassifierOutputWithNoAttention:"""Parameters----------pixel_values : torch.TensorInput tensor representing image pixel values.labels : Optional[Union[List[int], torch.Tensor]]Ground truth labels for training and computing loss.List of integers/tensor representing class IDs.Returns-------ImageClassifierOutputWithNoAttentionObject containing `logits` and `loss`."""self.model.training = False if labels is None else Truelogits = self.model(pixel_values)loss = Noneif self.model.training:labels = tensor(labels)ce_loss = nn.CrossEntropyLoss()loss = ce_loss(logits, labels)return ImageClassifierOutputWithNoAttention(loss = loss,logits = logits,)__all__ = ["EfficientNetModel","EfficientNetModelForImageClassification"]
config.json+2-3
configuration_efficientnet.py+12-10
modeling_efficientnet.py+125-51