Skip to content

Commit

Permalink
Fix cuda FloatTensor error
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-roddick committed Sep 30, 2019
1 parent c7d3ced commit ae7e4b8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.vscode
notebooks
experiments
tests

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
2 changes: 1 addition & 1 deletion oft/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .model import OftNet, huber_loss, hard_neg_mining_loss
from .data import KittiObjectDataset, ObjectEncoder, AugmentedObjectDataset
from .utils import MetricDict, Timer, convert_figure, make_grid
from .visualization import vis_score, vis_uncertainty
from .visualization import vis_score, vis_uncertainty, visualize_objects
8 changes: 4 additions & 4 deletions oft/data/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ def _encode_positions(self, positions, indices, grid):
positions = positions.index_select(0, indices.view(-1)).view(C, D, W, 3)

# Compute relative offsets and normalize
pos_offsets = (positions - centers) / self.pos_std
pos_offsets = (positions - centers) / self.pos_std.to(positions)
return pos_offsets.permute(0, 3, 1, 2)

def _encode_dimensions(self, classids, dimensions, indices):

# Convert mean and std to tensors
log_dim_mean = self.log_dim_mean[classids]
log_dim_std = self.log_dim_std[classids]
log_dim_mean = self.log_dim_mean.to(dimensions)[classids]
log_dim_std = self.log_dim_std.to(dimensions)[classids]

# Compute normalized log scale offset
dim_offsets = (torch.log(dimensions) - log_dim_mean) / log_dim_std
Expand All @@ -146,7 +146,7 @@ def _encode_empty(self, grid):
pos_offsets = grid.new_zeros((self.nclass, 3, depth-1, width-1))
dim_offsets = grid.new_zeros((self.nclass, 3, depth-1, width-1))
ang_offsets = grid.new_zeros((self.nclass, 2, depth-1, width-1))
mask = grid.new_zeros((self.nclass, depth-1, width-1)).byte()
mask = grid.new_zeros((self.nclass, depth-1, width-1)).bool()

return heatmaps, pos_offsets, dim_offsets, ang_offsets, mask

Expand Down
2 changes: 1 addition & 1 deletion oft/model/oftnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, num_classes=1, frontend='resnet18', topdown_layers=8,

# Construct frontend network
assert frontend in ['resnet18', 'resnet34'], 'unrecognised frontend'
self.frontend = getattr(resnet, frontend)(pretrained=True)
self.frontend = getattr(resnet, frontend)(pretrained=False)

# Lateral layers convert resnet outputs to a common feature size
self.lat8 = nn.Conv2d(128, 256, 1)
Expand Down
28 changes: 28 additions & 0 deletions oft/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ def gaussian_kernel(sigma=1., trunc=2.):
return kernel2d / kernel2d.sum()


def bbox_corners(obj):
"""
Return the 2D
"""

# Get corners of bounding box in object space
offsets = torch.tensor([
[-.5, 0., -.5], # Back-left lower
[ .5, 0., -.5], # Front-left lower
[-.5, 0., .5], # Back-right lower
[ .5, 0., .5], # Front-right lower
[-.5, -1., -.5], # Back-left upper
[ .5, -1., -.5], # Front-left upper
[-.5, -1., .5], # Back-right upper
[ .5, -1., .5], # Front-right upper
])
corners = offsets * torch.tensor(obj.dimensions)
# corners = corners[:, [2, 0, 1]]

# Apply y-axis rotation
corners = rotate(corners, torch.tensor(obj.angle))

# Apply translation
corners = corners + torch.tensor(obj.position)
return corners



def collate(batch):

idxs, images, calibs, objects, grids = zip(*batch)
Expand Down
3 changes: 1 addition & 2 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ def parse_args():
parser = ArgumentParser()

# Data options
parser.add_argument('--root', type=str,
default='data/kitti',
parser.add_argument('--root', type=str, default='data/kitti',
help='root directory of the KITTI dataset')
parser.add_argument('--grid-size', type=float, nargs=2, default=(80., 80.),
help='width and depth of validation grid, in meters')
Expand Down

0 comments on commit ae7e4b8

Please sign in to comment.