MCPcopy Create free account
hub / github.com/coperception/star / decode

Method decode

star/models/CNNNet.py:158–264  ·  view source on GitHub ↗

Decode the input features. Args: x (tensor): layer-0 features. x_1 (tensor): layer-1 features. x_2 (tensor): layer-2 features. x_3 (tensor): layer-3 features. x_4 (tensor): layer-4 featuers. batch (int): The batch size.

(
        self,
        x,
        x_1,
        x_2,
        x_3,
        x_4,
        batch,
        kd_flag=False,
        requires_adaptive_max_pool3d=False,
    )

Source from the content-addressed store, hash-verified

156 return [x, x_1, x_2, x_3, x_4]
157
158 def decode(
159 self,
160 x,
161 x_1,
162 x_2,
163 x_3,
164 x_4,
165 batch,
166 kd_flag=False,
167 requires_adaptive_max_pool3d=False,
168 ):
169 """Decode the input features.
170
171 Args:
172 x (tensor): layer-0 features.
173 x_1 (tensor): layer-1 features.
174 x_2 (tensor): layer-2 features.
175 x_3 (tensor): layer-3 features.
176 x_4 (tensor): layer-4 featuers.
177 batch (int): The batch size.
178 kd_flag (bool, optional): Required to be true for DiscoNet. Defaults to False.
179 requires_adaptive_max_pool3d (bool, optional): If set to true, use adaptive max pooling 3d. Defaults to False.
180
181 Returns:
182 if kd_flag is true, return a list of output from layer-8 to layer-5
183 else return a list of a single element: the output after passing through the decoder
184 """
185 # -------------------------------- Decoder Path --------------------------------
186 x_5 = F.relu(
187 self.bn5_1(
188 self.conv5_1(
189 torch.cat((F.interpolate(x_4, scale_factor=(2, 2)), x_3), dim=1)
190 )
191 )
192 )
193 x_5 = F.relu(self.bn5_2(self.conv5_2(x_5)))
194
195 x_2 = x_2.view(batch, -1, x_2.size(1), x_2.size(2), x_2.size(3))
196 x_2 = x_2.permute(0, 2, 1, 3, 4).contiguous()
197 x_2 = (
198 F.adaptive_max_pool3d(x_2, (1, None, None))
199 if requires_adaptive_max_pool3d
200 else x_2
201 )
202 x_2 = x_2.permute(0, 2, 1, 3, 4).contiguous()
203 x_2 = x_2.view(-1, x_2.size(2), x_2.size(3), x_2.size(4)).contiguous()
204
205 x_6 = F.relu(
206 self.bn6_1(
207 self.conv6_1(
208 torch.cat((F.interpolate(x_5, scale_factor=(2, 2)), x_2), dim=1)
209 )
210 )
211 )
212 x_6 = F.relu(self.bn6_2(self.conv6_2(x_6)))
213
214 x_1 = x_1.view(batch, -1, x_1.size(1), x_1.size(2), x_1.size(3))
215 x_1 = x_1.permute(0, 2, 1, 3, 4).contiguous()

Callers 1

forwardMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected