Skip to content

Commit

Permalink
use google drive for large files
Browse files Browse the repository at this point in the history
  • Loading branch information
han-cai committed Jul 19, 2023
1 parent c6ea569 commit 8798322
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
15 changes: 10 additions & 5 deletions ofa/model_zoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json
import torch
import gdown

from ofa.utils import download_url
from ofa.imagenet_classification.networks import get_net_by_name, proxyless_base
Expand Down Expand Up @@ -59,6 +60,7 @@ def ofa_specialized(net_id: str, pretrained=True):

def ofa_net(net_id, pretrained=True):
url_base = "https://raw.githubusercontent.com/han-cai/files/master/ofa/ofa_nets/"
googledrive = False
if net_id == "ofa_proxyless_d234_e346_k357_w1.3":
net = OFAProxylessNASNets(
dropout_rate=0,
Expand Down Expand Up @@ -91,15 +93,18 @@ def ofa_net(net_id, pretrained=True):
width_mult_list=[0.65, 0.8, 1.0],
)
net_id = "ofa_resnet50_d0-1-2_e0.2-0.25-0.35_w0.65-0.8-1.0"
url_base = "https://media.githubusercontent.com/media/han-cai/files/master/ofa/ofa_nets/"
url_base = "https://drive.google.com/uc?id=1xy6VIPEHXqbbqNu3xEZUxhp5FbTVs5cQ"
googledrive = True
else:
raise ValueError("Not supported: %s" % net_id)

if pretrained:
init = torch.load(
download_url(url_base + net_id, model_dir=".torch/ofa_nets"),
map_location="cpu",
)["state_dict"]
if googledrive:
pt_path = f".torch/ofa_nets/{net_id}"
gdown.download(url_base, pt_path, quiet=False)
else:
pt_path = download_url(url_base + net_id, model_dir=".torch/ofa_nets")
init = torch.load(pt_path, map_location="cpu")["state_dict"]
net.load_state_dict(init)
return net

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
torch
torchvision
filelock
filelock
gdown
3 changes: 2 additions & 1 deletion tutorial/ofa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@
" # if 'imagenet_data_path' is empty, download a subset of ImageNet containing 2000 images (~250M) for test\n",
" if not os.path.isdir(imagenet_data_path):\n",
" os.makedirs(imagenet_data_path, exist_ok=True)\n",
" download_url('https://media.githubusercontent.com/media/han-cai/files/master/ofa/imagenet_1k.zip', model_dir='data')\n",
" import gdown\n",
" gdown.download(\"https://drive.google.com/uc?id=18gEZh9xzsiHi9yqWaCcxqKbYrjW4IPRB\", \"data/imagenet_1k.zip\")\n",
" ! cd data && unzip imagenet_1k 1>/dev/null && cd ..\n",
" ! cp -r data/imagenet_1k/* $imagenet_data_path\n",
" ! rm -rf data\n",
Expand Down

0 comments on commit 8798322

Please sign in to comment.