Skip to content

Commit

Permalink
Fix issues with CaDDN (open-mmlab#542)
Browse files Browse the repository at this point in the history
* Download DeepLabV3 if not available yet

* Fix dtype issue

Fix RuntimeError: expected backend CPU and dtype Float but got backend CPU and dtype Long
  • Loading branch information
MartinHahner authored May 22, 2021
1 parent aaf9cbe commit 7efdf02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, grid_size, pc_range, disc_cfg):
"""
super().__init__()
self.dtype = torch.float32
self.grid_size = torch.as_tensor(grid_size)
self.grid_size = torch.as_tensor(grid_size, dtype=self.dtype)
self.pc_range = pc_range
self.out_of_bounds_val = -2
self.disc_cfg = disc_cfg
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from collections import OrderedDict
from pathlib import Path
from torch import hub

import numpy as np
import torch
Expand Down Expand Up @@ -56,6 +58,15 @@ def get_model(self, constructor):
# Update weights
if self.pretrained_path is not None:
model_dict = model.state_dict()

# Download pretrained model if not available yet
checkpoint_path = Path(self.pretrained_path)
if not checkpoint_path.exists():
checkpoint = checkpoint_path.name
save_dir = checkpoint_path.parent
save_dir.mkdir(parents=True)
url = f'https://download.pytorch.org/models/{checkpoint}'
hub.load_state_dict_from_url(url, save_dir)

# Get pretrained state dict
pretrained_dict = torch.load(self.pretrained_path)
Expand Down

0 comments on commit 7efdf02

Please sign in to comment.