Safemotion Lib
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
fastreid.modeling.backbones.osnet.ChannelGate Class Reference
Inheritance diagram for fastreid.modeling.backbones.osnet.ChannelGate:

Public Member Functions

 __init__ (self, in_channels, num_gates=None, return_gates=False, gate_activation='sigmoid', reduction=16, layer_norm=False)
 
 forward (self, x)
 

Public Attributes

 return_gates
 
 global_avgpool
 
 fc1
 
 norm1
 
 relu
 
 fc2
 
 gate_activation
 

Detailed Description

A mini-network that generates channel-wise gates conditioned on input tensor.

Definition at line 171 of file osnet.py.

Constructor & Destructor Documentation

◆ __init__()

fastreid.modeling.backbones.osnet.ChannelGate.__init__ ( self,
in_channels,
num_gates = None,
return_gates = False,
gate_activation = 'sigmoid',
reduction = 16,
layer_norm = False )

Definition at line 174 of file osnet.py.

182 ):
183 super(ChannelGate, self).__init__()
184 if num_gates is None: num_gates = in_channels
185 self.return_gates = return_gates
186
187 self.global_avgpool = nn.AdaptiveAvgPool2d(1)
188
189 self.fc1 = nn.Conv2d(
190 in_channels,
191 in_channels // reduction,
192 kernel_size=1,
193 bias=True,
194 padding=0
195 )
196 self.norm1 = None
197 if layer_norm: self.norm1 = nn.LayerNorm((in_channels // reduction, 1, 1))
198 self.relu = nn.ReLU(inplace=True)
199 self.fc2 = nn.Conv2d(
200 in_channels // reduction,
201 num_gates,
202 kernel_size=1,
203 bias=True,
204 padding=0
205 )
206 if gate_activation == 'sigmoid':
207 self.gate_activation = nn.Sigmoid()
208 elif gate_activation == 'relu':
209 self.gate_activation = nn.ReLU(inplace=True)
210 elif gate_activation == 'linear':
211 self.gate_activation = nn.Identity()
212 else:
213 raise RuntimeError(
214 "Unknown gate activation: {}".format(gate_activation)
215 )
216

Member Function Documentation

◆ forward()

fastreid.modeling.backbones.osnet.ChannelGate.forward ( self,
x )

Definition at line 217 of file osnet.py.

217 def forward(self, x):
218 input = x
219 x = self.global_avgpool(x)
220 x = self.fc1(x)
221 if self.norm1 is not None: x = self.norm1(x)
222 x = self.relu(x)
223 x = self.fc2(x)
224 x = self.gate_activation(x)
225 if self.return_gates: return x
226 return input * x
227
228

Member Data Documentation

◆ fc1

fastreid.modeling.backbones.osnet.ChannelGate.fc1

Definition at line 189 of file osnet.py.

◆ fc2

fastreid.modeling.backbones.osnet.ChannelGate.fc2

Definition at line 199 of file osnet.py.

◆ gate_activation

fastreid.modeling.backbones.osnet.ChannelGate.gate_activation

Definition at line 207 of file osnet.py.

◆ global_avgpool

fastreid.modeling.backbones.osnet.ChannelGate.global_avgpool

Definition at line 187 of file osnet.py.

◆ norm1

fastreid.modeling.backbones.osnet.ChannelGate.norm1

Definition at line 196 of file osnet.py.

◆ relu

fastreid.modeling.backbones.osnet.ChannelGate.relu

Definition at line 198 of file osnet.py.

◆ return_gates

fastreid.modeling.backbones.osnet.ChannelGate.return_gates

Definition at line 185 of file osnet.py.


The documentation for this class was generated from the following file: