def forward(self, x): if self.normalize: x = normalize_imagenet(x) f3,f2,f1 = self.features(x) # f3: 512 f2: 256 * 14 * 14 f1: 128 * 28 * 28 # full kmax pooling f1 = f1.detach() f1 = kmax_pooling(f1,1,2) f1 = f1.view(f1.size(0), -1) f1 = self.f1_fc(f1) f2 = f2.detach() f2 = kmax_pooling(f2,1,8) f2 = f2.view(f2.size(0), -1) f2 = self.f2_fc(f2) f3 = self.fc3(f3) f2 = self.fc2(f2) f1 = self.fc1(f1) if self.batch_norm: f3 = self.f3_bn(f3) f2 = self.f2_bn(f2) f1 = self.f1_bn(f1) return f3, f2, f1
def forward(self, x): batch_size = x.size(0) net = normalize_imagenet(x) net = self.convnet(net) net = net.view(batch_size, 256 * 3 * 3) out = self.fc_out(net) return out
def call(self, x, training=False): if self.normalize: x = normalize_imagenet(x) x = self.conv1(x) x = self.bn1(x, training=training) x = tf.nn.relu(x) x = self.pool1(x) x = self.layer1(x, training=training) x = self.layer2(x, training=training) x = self.layer3(x, training=training) x = self.layer4(x, training=training) x = self.avgpool(x) out = self.fc(x) return out
def forward_local(self, data, pts): assert self.local world_mat = data['world_mat'] camera_mat = data['camera_mat'] x = data[None] pts = transform_points(pts, world_mat) points_img = project_to_camera(pts, camera_mat) points_img = points_img.unsqueeze(1) local_feat_maps = [] if self.normalize: x = normalize_imagenet(x) x = self.features.conv1(x) x = self.features.bn1(x) x = self.features.relu(x) x = self.features.maxpool(x) # 64 * 112 * 112 x = self.features.layer1(x) local_feat_maps.append(x) # 64 * 56 * 56 x = self.features.layer2(x) local_feat_maps.append(x) # 128 * 28 * 28 x = self.features.layer3(x) local_feat_maps.append(x) # 256 * 14 * 14 x = self.features.layer4(x) local_feat_maps.append(x) # 512 * 7 * 7 x = self.features.avgpool(x) x = x.view(x.size(0), -1) x = self.fc(x) # get local feats local_feats = [] for f in local_feat_maps: #f = f.detach() f = F.grid_sample(f, points_img, mode='nearest') f = f.squeeze(2) local_feats.append(f) local_feats = torch.cat(local_feats, dim=1) local_feats = local_feats.transpose(1, 2) # batch * n_pts * f_dim local_feats = self.local_fc(local_feats) # x: B * c_dim # local: feats B * n_pts * c_dim return x, local_feats
def forward(self, x, h, u, time): if self.normalize: x = normalize_imagenet(x) net = self.features(x) fc = self.fc(net) rect = self.leaky_relu(fc) t_x_s_update = self.t_x_s_update(rect, h, time) t_x_s_reset = self.t_x_s_reset(rect, h, time) update_gate = self.sigmoid(t_x_s_update) complement_update_gate = 1 - update_gate reset_gate = self.sigmoid(t_x_s_reset) rs = reset_gate * h t_x_rs = self.t_x_rs(rect, rs, time) tanh_t_x_rs = self.tanh(t_x_rs) gru_out = update_gate * h + complement_update_gate * tanh_t_x_rs return gru_out, update_gate
def forward(self, x): if self.normalize: x = normalize_imagenet(x) net = self.features(x) out = self.fc(net) return out
def call(self, x, training=False): if self.normalize: x = normalize_imagenet(x) net = self.features(x, training=training) out = self.fc(net) return out
def encode_first_step(self, x): if self.normalize: x = normalize_imagenet(x) f3,fs2,fs1 = self.features.calc_feature_maps(x) return f3, fs2, fs1
def encode_first_step(self, x): if self.normalize: x = normalize_imagenet(x) f3,f2,f1 = self.features(x) return f3, f2, f1