-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff7e3af
commit e0cfc91
Showing
3 changed files
with
55 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import torch | ||
|
||
from vision_toolbox.backbones import ViT | ||
from vision_toolbox.utils import torch_hub_download | ||
|
||
|
||
def test_resize_pe(): | ||
m = ViT.from_config("Ti", 16, 224) | ||
m(torch.randn(1, 3, 224, 224)) | ||
m.resize_pe(256) | ||
m(torch.randn(1, 3, 256, 256)) | ||
|
||
|
||
def test_from_jax(): | ||
url = ( | ||
"https://storage.googleapis.com/vit_models/augreg/Ti_16-i21k-300ep-lr_0.001-aug_none-wd_0.03-do_0.0-sd_0.0.npz" | ||
) | ||
m = ViT.from_jax_weights(torch_hub_download(url)) | ||
m(torch.randn(1, 3, 224, 224)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import os | ||
|
||
import torch | ||
|
||
|
||
def torch_hub_download(url: str) -> str: | ||
save_path = os.path.join(torch.hub.get_dir(), os.path.basename(url)) | ||
if not os.path.exists(save_path): | ||
torch.hub.download_url_to_file(url, save_path) | ||
return save_path |