bugfix in deepsets

This commit is contained in:
Johannes Fischer
2021-07-22 18:44:12 +02:00
parent 91d052445e
commit 1c22bd6111
4 changed files with 8 additions and 3 deletions

View File

@@ -63,7 +63,7 @@ class DeepSetsModule(nn.Module):
# shape (B, max_nv) # shape (B, max_nv)
notnan_mask = torch.all(~torch.isnan(x), dim=-1) notnan_mask = torch.all(~torch.isnan(x), dim=-1)
# create zero tensor of shape (B, max_nv, latent_dim) to store phi evaluations in # create zero tensor of shape (B, max_nv, latent_dim) to store phi evaluations in
latent = torch.zeros([*x.shape[:-1], self.latent_dim]) latent = torch.zeros([*x.shape[:-1], self.latent_dim], dtype=x.dtype)
# evaluate phi for all not NaN entries # evaluate phi for all not NaN entries
# x[batch_dynamic_mask] has shape (notnan_mask.sum(), input_dim) # x[batch_dynamic_mask] has shape (notnan_mask.sum(), input_dim)
latent[notnan_mask] = self.phi(x[notnan_mask]) latent[notnan_mask] = self.phi(x[notnan_mask])

View File

@@ -42,6 +42,6 @@ class DeepSetsPolicy(Policy, nn.Module):
# cat path_x, path_y to tensor of dim (B, 2*P) # cat path_x, path_y to tensor of dim (B, 2*P)
path = torch.cat([sample["path_x"], sample["path_y"]], dim=-1) path = torch.cat([sample["path_x"], sample["path_y"]], dim=-1)
path = self.path_net(path) path = self.path_net(path)
x = torch.cat([ego, relative, path]) x = torch.cat([ego, relative, path], dim=-1)
x = self.head(x) x = self.head(x)
return x return x

View File

@@ -9,6 +9,9 @@ with open(config_path, 'r') as cfg:
filestr = 'tests/policies/base_' filestr = 'tests/policies/base_'
batch = pickle.load(open(filestr+'_test_batch.pkl', 'rb')) batch = pickle.load(open(filestr+'_test_batch.pkl', 'rb'))
batch['relative_state'] = batch['relative_state'].float()
policy = BehaviorCloningPolicy.load_model(config, filestr) policy = BehaviorCloningPolicy.load_model(config, filestr)
policy.policy = policy.policy.type(batch['state'].dtype)
action = policy(batch) action = policy(batch)

View File

@@ -25,4 +25,6 @@ def test_deepsets_policy():
"path_y": path_y, "path_y": path_y,
} }
module(sample) module(sample)
# TODO: Refine test to also test for batch data