Skip to content

Commit

Permalink
Merge pull request #53 from discovery-unicamp/fixing-test-issues
Browse files Browse the repository at this point in the history
chore: Update position_embedding.py and test files
  • Loading branch information
GabrielBG0 authored May 3, 2024
2 parents 6d3dcec + 28e29fd commit 11f80d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions minerva/utils/position_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def get_2d_sincos_pos_embed(embed_dim, grid_size, cls_token=False):
return:
pos_embed: [grid_size*grid_size, embed_dim] or [1+grid_size*grid_size, embed_dim] (w/ or w/o cls_token)
"""
grid_h = np.arange(grid_size, dtype=np.float32)
grid_w = np.arange(grid_size, dtype=np.float32)
grid_h = np.arange(grid_size, dtype=float)
grid_w = np.arange(grid_size, dtype=float)
grid = np.meshgrid(grid_w, grid_h) # here w goes first
grid = np.stack(grid, axis=0)

Expand Down Expand Up @@ -49,7 +49,7 @@ def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
out: (M, D)
"""
assert embed_dim % 2 == 0
omega = np.arange(embed_dim // 2, dtype=np.float)
omega = np.arange(embed_dim // 2, dtype=float)
omega /= embed_dim / 2.0
omega = 1.0 / 10000**omega # (D/2,)

Expand Down
14 changes: 7 additions & 7 deletions tests/models/nets/test_setr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


def test_wisenet_loss():
model = SETR_PUP()
model = SETR_PUP(image_size=16)
batch_size = 2
x = torch.rand(2, 3, 512, 512)
mask = torch.rand(2, 1, 512, 512).long()
x = torch.rand(2, 3, 16, 16)
mask = torch.rand(2, 1, 16, 16).long()

# Do the training step
loss = model.training_step((x, mask), 0).item()
Expand All @@ -17,11 +17,11 @@ def test_wisenet_loss():


def test_wisenet_predict():
model = SETR_PUP()
model = SETR_PUP(image_size=16)
batch_size = 2
mask_shape = (batch_size, 1000, 512, 512) # (2, 1, 500, 500)
x = torch.rand(2, 3, 512, 512)
mask = torch.rand(2, 1, 512, 512).long()
mask_shape = (batch_size, 1000, 16, 16) # (2, 1, 500, 500)
x = torch.rand(2, 3, 16, 16)
mask = torch.rand(2, 1, 16, 16).long()

# Do the prediction step
preds = model.predict_step((x, mask), 0)
Expand Down
2 changes: 1 addition & 1 deletion tests/models/nets/test_sfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
]


# @pytest.mark.parametrize("model_cls,img_size", test_models)
@pytest.mark.parametrize("model_cls,img_size", test_models)
def test_sfm_pretrain_forward(model_cls, img_size):
# Test the class instantiation
model = model_cls(img_size=img_size, in_chans=1, norm_pix_loss=False)
Expand Down

0 comments on commit 11f80d5

Please sign in to comment.