MCPcopy Create free account
hub / github.com/GeWu-Lab/AnyTouch2 / forward

Method forward

model/linear_probe.py:215–252  ·  view source on GitHub ↗
(self, x, sensor_type = None, return_feature = False)

Source from the content-addressed store, hash-verified

213 trunc_normal_(self.head.weight, std=0.01)
214
215 def forward(self, x, sensor_type = None, return_feature = False):
216
217 with torch.no_grad():
218 if self.pooling == 'none':
219 x = self.tactile_model(x, sensor_type = sensor_type, probe=True)
220 out = x
221 else:
222 if self.pooling == 'cls':
223 # out = self.touch_projection(x.pooler_output)
224 x = self.tactile_model(x, sensor_type = sensor_type, probe=True, get_cls=True)
225 out = x
226 elif self.pooling == 'last':
227 x = self.tactile_model(x, sensor_type = sensor_type, probe=True, get_cls=False)
228 out = x[:, -self.single_patch_num:, :]
229 else:
230 x = self.tactile_model(x, sensor_type = sensor_type, probe=True, get_cls=False)
231 if self.use_sensor_token:
232 out = x[:, 6:, :]
233 else:
234 out = x[:, 1:, :]
235
236 feature = out
237 # print(out.shape)
238
239 if self.pooling == 'none':
240 out = self.head(out)
241
242 else:
243 if self.pooling == 'cls':
244 out = self.head(out)
245
246 elif self.pooling == 'global' or self.pooling == 'last':
247 out = self.head(out.mean(dim=1))
248
249
250 if return_feature:
251 return out, feature
252 return out

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected