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

Method __init__

extra/models/efficientnet.py:8–34  ·  view source on GitHub ↗
(self, kernel_size, strides, expand_ratio, input_filters, output_filters, se_ratio, has_se, track_running_stats=True)

Source from the content-addressed store, hash-verified

6
7class MBConvBlock:
8 def __init__(self, kernel_size, strides, expand_ratio, input_filters, output_filters, se_ratio, has_se, track_running_stats=True):
9 oup = expand_ratio * input_filters
10 if expand_ratio != 1:
11 self._expand_conv = Tensor.glorot_uniform(oup, input_filters, 1, 1)
12 self._bn0 = BatchNorm2d(oup, track_running_stats=track_running_stats)
13 else:
14 self._expand_conv = None
15
16 self.strides = strides
17 if strides == (2,2):
18 self.pad = [(kernel_size-1)//2-1, (kernel_size-1)//2]*2
19 else:
20 self.pad = [(kernel_size-1)//2]*4
21
22 self._depthwise_conv = Tensor.glorot_uniform(oup, 1, kernel_size, kernel_size)
23 self._bn1 = BatchNorm2d(oup, track_running_stats=track_running_stats)
24
25 self.has_se = has_se
26 if self.has_se:
27 num_squeezed_channels = max(1, int(input_filters * se_ratio))
28 self._se_reduce = Tensor.glorot_uniform(num_squeezed_channels, oup, 1, 1)
29 self._se_reduce_bias = Tensor.zeros(num_squeezed_channels)
30 self._se_expand = Tensor.glorot_uniform(oup, num_squeezed_channels, 1, 1)
31 self._se_expand_bias = Tensor.zeros(oup)
32
33 self._project_conv = Tensor.glorot_uniform(output_filters, oup, 1, 1)
34 self._bn2 = BatchNorm2d(output_filters, track_running_stats=track_running_stats)
35
36 def __call__(self, inputs):
37 x = inputs

Callers

nothing calls this directly

Calls 2

glorot_uniformMethod · 0.80
zerosMethod · 0.80

Tested by

no test coverage detected