zhangfaen commited on
Commit
bec1610
·
verified ·
1 Parent(s): f63af4d

Upload configuration_resnet.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. configuration_resnet.py +46 -0
configuration_resnet.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+ from typing import List
3
+ from pprint import pprint
4
+
5
+
6
+ class ResnetConfig(PretrainedConfig):
7
+ model_type = "faen_resnet"
8
+
9
+ def __init__(
10
+ self,
11
+ block_type="bottleneck",
12
+ layers: List[int] = [3, 4, 6, 3],
13
+ num_classes: int = 1000,
14
+ input_channels: int = 3,
15
+ cardinality: int = 1,
16
+ base_width: int = 64,
17
+ stem_width: int = 64,
18
+ stem_type: str = "",
19
+ avg_down: bool = False,
20
+ **kwargs,
21
+ ):
22
+ if block_type not in ["basic", "bottleneck"]:
23
+ raise ValueError(f"`block_type` must be 'basic' or bottleneck', got {block_type}.")
24
+ if stem_type not in ["", "deep", "deep-tiered"]:
25
+ raise ValueError(f"`stem_type` must be '', 'deep' or 'deep-tiered', got {stem_type}.")
26
+
27
+ self.block_type = block_type
28
+ self.layers = layers
29
+ self.num_classes = num_classes
30
+ self.input_channels = input_channels
31
+ self.cardinality = cardinality
32
+ self.base_width = base_width
33
+ self.stem_width = stem_width
34
+ self.stem_type = stem_type
35
+ self.avg_down = avg_down
36
+ super().__init__(**kwargs)
37
+
38
+ if __name__ == "__main__":
39
+ resnet50d_config = ResnetConfig(block_type="bottleneck", stem_width=32, stem_type="deep", avg_down=True)
40
+ print("init a ResnetConfig, it is:\n")
41
+ pprint(resnet50d_config)
42
+ resnet50d_config.save_pretrained("./")
43
+ resnet50d_config = ResnetConfig.from_pretrained("./")
44
+ print("\n")
45
+ print("saved to file config.json and reload it from config.json and it is:\n")
46
+ pprint(resnet50d_config)