Felix Marty commited on
Commit
74b941a
1 Parent(s): c7d4f5e
config.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
- "_name_or_path": "hf-internal-testing/tiny-random-resnet",
3
  "architectures": [
4
- "ResNetForImageClassification"
5
  ],
6
  "depths": [
7
  3,
@@ -2024,6 +2024,14 @@
2024
  "layer_type": "bottleneck",
2025
  "model_type": "resnet",
2026
  "num_channels": 3,
 
 
 
 
 
 
 
 
2027
  "torch_dtype": "float32",
2028
- "transformers_version": "4.22.0.dev0"
2029
  }
 
1
  {
2
+ "_name_or_path": "/home/fxmarty/hf_internship/tiny-testing-remote-code",
3
  "architectures": [
4
+ "ResNetCustomForImageClassification"
5
  ],
6
  "depths": [
7
  3,
 
2024
  "layer_type": "bottleneck",
2025
  "model_type": "resnet",
2026
  "num_channels": 3,
2027
+ "out_features": null,
2028
+ "stage_names": [
2029
+ "stem",
2030
+ "stage1",
2031
+ "stage2",
2032
+ "stage3",
2033
+ "stage4"
2034
+ ],
2035
  "torch_dtype": "float32",
2036
+ "transformers_version": "4.26.0.dev0"
2037
  }
create_model.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoConfig
2
+
3
+ from modeling import ResNetCustomForImageClassification
4
+
5
+ cfg = AutoConfig.from_pretrained("/home/fxmarty/hf_internship/tiny-testing-remote-code")
6
+ model = ResNetCustomForImageClassification(cfg)
7
+
8
+ model.save_pretrained("/home/fxmarty/hf_internship/tiny-testing-remote-code")
inference.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
2
+ import torch
3
+ from datasets import load_dataset
4
+
5
+ model = AutoModelForImageClassification.from_pretrained(".", trust_remote_code=True)
6
+
7
+ dataset = load_dataset("huggingface/cats-image")
8
+ image = dataset["test"]["image"][0]
9
+
10
+ feature_extractor = AutoFeatureExtractor.from_pretrained(".")
11
+
12
+ inputs = feature_extractor(image, return_tensors="pt")
13
+
14
+ with torch.no_grad():
15
+ logits = model(**inputs).logits
16
+
17
+ # model predicts one of the 1000 ImageNet classes
18
+ predicted_label = logits.argmax(-1).item()
19
+ print(model.config.id2label[predicted_label])
modeling.py → modeling_resnet.py RENAMED
@@ -21,22 +21,22 @@ import torch.utils.checkpoint
21
  from torch import Tensor, nn
22
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
23
 
24
- from ...activations import ACT2FN
25
- from ...modeling_outputs import (
26
  BackboneOutput,
27
  BaseModelOutputWithNoAttention,
28
  BaseModelOutputWithPoolingAndNoAttention,
29
  ImageClassifierOutputWithNoAttention,
30
  )
31
- from ...modeling_utils import BackboneMixin, PreTrainedModel
32
- from ...utils import (
33
  add_code_sample_docstrings,
34
  add_start_docstrings,
35
  add_start_docstrings_to_model_forward,
36
  logging,
37
  replace_return_docstrings,
38
  )
39
- from .configuration_resnet import ResNetConfig
40
 
41
 
42
  logger = logging.get_logger(__name__)
@@ -356,7 +356,7 @@ class ResNetModel(ResNetPreTrainedModel):
356
  """,
357
  RESNET_START_DOCSTRING,
358
  )
359
- class ResNetForImageClassification(ResNetPreTrainedModel):
360
  def __init__(self, config):
361
  super().__init__(config)
362
  self.num_labels = config.num_labels
 
21
  from torch import Tensor, nn
22
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
23
 
24
+ from transformers.activations import ACT2FN
25
+ from transformers.modeling_outputs import (
26
  BackboneOutput,
27
  BaseModelOutputWithNoAttention,
28
  BaseModelOutputWithPoolingAndNoAttention,
29
  ImageClassifierOutputWithNoAttention,
30
  )
31
+ from transformers.modeling_utils import BackboneMixin, PreTrainedModel
32
+ from transformers.utils import (
33
  add_code_sample_docstrings,
34
  add_start_docstrings,
35
  add_start_docstrings_to_model_forward,
36
  logging,
37
  replace_return_docstrings,
38
  )
39
+ from transformers import ResNetConfig
40
 
41
 
42
  logger = logging.get_logger(__name__)
 
356
  """,
357
  RESNET_START_DOCSTRING,
358
  )
359
+ class ResNetCustomForImageClassification(ResNetPreTrainedModel):
360
  def __init__(self, config):
361
  super().__init__(config)
362
  self.num_labels = config.num_labels
pytorch_model.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:7e126c7921476a0e02a4aa614166508c9a4dcc15f4c6b3a7503ec8f324dd2e7c
3
- size 399041
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b41ec5a4bea6eee004ec1213ed11685f6d61f457f8e4ce91190dabb9b8edf680
3
+ size 401037