MCPcopy
hub / github.com/tinygrad/tinygrad / __init__

Method __init__

extra/models/efficientnet.py:55–124  ·  view source on GitHub ↗
(self, number=0, classes=1000, has_se=True, track_running_stats=True, input_channels=3, has_fc_output=True)

Source from the content-addressed store, hash-verified

53
54class EfficientNet:
55 def __init__(self, number=0, classes=1000, has_se=True, track_running_stats=True, input_channels=3, has_fc_output=True):
56 self.number = number
57 global_params = [
58 # width, depth
59 (1.0, 1.0), # b0
60 (1.0, 1.1), # b1
61 (1.1, 1.2), # b2
62 (1.2, 1.4), # b3
63 (1.4, 1.8), # b4
64 (1.6, 2.2), # b5
65 (1.8, 2.6), # b6
66 (2.0, 3.1), # b7
67 (2.2, 3.6), # b8
68 (4.3, 5.3), # l2
69 ][max(number,0)]
70
71 def round_filters(filters):
72 multiplier = global_params[0]
73 divisor = 8
74 filters *= multiplier
75 new_filters = max(divisor, int(filters + divisor / 2) // divisor * divisor)
76 if new_filters < 0.9 * filters: # prevent rounding by more than 10%
77 new_filters += divisor
78 return int(new_filters)
79
80 def round_repeats(repeats):
81 return int(math.ceil(global_params[1] * repeats))
82
83 out_channels = round_filters(32)
84 self._conv_stem = Tensor.glorot_uniform(out_channels, input_channels, 3, 3)
85 self._bn0 = BatchNorm2d(out_channels, track_running_stats=track_running_stats)
86 blocks_args = [
87 [1, 3, (1,1), 1, 32, 16, 0.25],
88 [2, 3, (2,2), 6, 16, 24, 0.25],
89 [2, 5, (2,2), 6, 24, 40, 0.25],
90 [3, 3, (2,2), 6, 40, 80, 0.25],
91 [3, 5, (1,1), 6, 80, 112, 0.25],
92 [4, 5, (2,2), 6, 112, 192, 0.25],
93 [1, 3, (1,1), 6, 192, 320, 0.25],
94 ]
95
96 if self.number == -1:
97 blocks_args = [
98 [1, 3, (2,2), 1, 32, 40, 0.25],
99 [1, 3, (2,2), 1, 40, 80, 0.25],
100 [1, 3, (2,2), 1, 80, 192, 0.25],
101 [1, 3, (2,2), 1, 192, 320, 0.25],
102 ]
103 elif self.number == -2:
104 blocks_args = [
105 [1, 9, (8,8), 1, 32, 320, 0.25],
106 ]
107
108 self._blocks = []
109 for num_repeats, kernel_size, strides, expand_ratio, input_filters, output_filters, se_ratio in blocks_args:
110 input_filters, output_filters = round_filters(input_filters), round_filters(output_filters)
111 for n in range(round_repeats(num_repeats)):
112 self._blocks.append(MBConvBlock(kernel_size, strides, expand_ratio, input_filters, output_filters, se_ratio, has_se=has_se, track_running_stats=track_running_stats))

Callers

nothing calls this directly

Calls 4

MBConvBlockClass · 0.85
glorot_uniformMethod · 0.80
appendMethod · 0.80
zerosMethod · 0.80

Tested by

no test coverage detected