Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update position_embedding.py and correct test files #53

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading