Skip to content

Commit

Permalink
misc small changes
Browse files Browse the repository at this point in the history
Summary: on testing, typing

Reviewed By: rbgirshick

Differential Revision: D21158243

fbshipit-source-id: 84237575f3a65816b6988fa8994a8106853497e7
  • Loading branch information
ppwwyyxx authored and facebook-github-bot committed Apr 21, 2020
1 parent 4bd92bb commit 273e3b9
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ jobs:
- run:
name: Run Unit Tests
command: |
docker exec -it d2 python3 -m unittest discover -v -s /detectron2/tests
docker exec -e CIRCLECI=true -it d2 python3 -m unittest discover -v -s /detectron2/tests
workflows:
version: 2
Expand Down
2 changes: 2 additions & 0 deletions detectron2/checkpoint/detection_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def _load_model(self, checkpoint):
checkpoint["model"] = model_state_dict
# for non-caffe2 models, use standard ways to load it
incompatible = super()._load_model(checkpoint)
if incompatible is None: # support older versions of fvcore
return None

model_buffers = dict(self.model.named_buffers(recurse=False))
for k in ["pixel_mean", "pixel_std"]:
Expand Down
2 changes: 2 additions & 0 deletions detectron2/data/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class AspectRatioGroupedDataset(data.IterableDataset):
Batch data that have similar aspect ratio together.
In this implementation, images whose aspect ratio < (or >) 1 will
be batched together.
This improves training speed because the images then need less padding
to form a batch.
It assumes the underlying dataset produces dicts with "width" and "height" keys.
It will then produce a list of original dicts with length = batch_size,
Expand Down
4 changes: 2 additions & 2 deletions detectron2/layers/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def forward(self, x):
return _NewEmptyTensorOp.apply(x, output_shape)


if False: # not yet fixed in pytorch
if TORCH_VERSION > (1, 5):
Linear = torch.nn.Linear
else:

Expand Down Expand Up @@ -182,7 +182,7 @@ def interpolate(input, size=None, scale_factor=None, mode="nearest", align_corne
"""
A wrapper around :func:`torch.nn.functional.interpolate` to support zero-size tensor.
"""
if input.numel() > 0:
if TORCH_VERSION > (1, 4) or input.numel() > 0:
return torch.nn.functional.interpolate(
input, size, scale_factor, mode, align_corners=align_corners
)
Expand Down
4 changes: 2 additions & 2 deletions detectron2/modeling/anchor_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __iter__(self):
return iter(self._buffers.values())


def _create_grid_offsets(size, stride, offset, device):
def _create_grid_offsets(size: List[int], stride: int, offset: float, device: torch.device):
grid_height, grid_width = size
shifts_x = torch.arange(
offset * stride, grid_width * stride, step=stride, dtype=torch.float32, device=device
Expand Down Expand Up @@ -154,7 +154,7 @@ def num_cell_anchors(self):
"""
return [len(cell_anchors) for cell_anchors in self.cell_anchors]

def _grid_anchors(self, grid_sizes):
def _grid_anchors(self, grid_sizes: List[List[int]]):
anchors = []
for size, stride, base_anchors in zip(grid_sizes, self.strides, self.cell_anchors):
shift_x, shift_y = _create_grid_offsets(size, stride, self.offset, base_anchors.device)
Expand Down
1 change: 0 additions & 1 deletion tests/data/test_detection_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np
import unittest
import pycocotools.mask as mask_util
import torch

from detectron2.data import detection_utils
from detectron2.data import transforms as T
Expand Down
7 changes: 6 additions & 1 deletion tests/modeling/test_anchor_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def test_default_anchor_generator_centered(self):
# only the last two dimensions of features matter here
num_images = 2
features = {"stage3": torch.rand(num_images, 96, 1, 2)}
anchors = anchor_generator([features["stage3"]])
expected_anchor_tensor = torch.tensor(
[
[-30.0, -6.0, 34.0, 10.0],
Expand All @@ -69,9 +68,15 @@ def test_default_anchor_generator_centered(self):
]
)

anchors = anchor_generator([features["stage3"]])
for i in range(num_images):
assert torch.allclose(anchors[i][0].tensor, expected_anchor_tensor)

# doesn't work yet
# anchors = torch.jit.script(anchor_generator)([features["stage3"]])
# for i in range(num_images):
# assert torch.allclose(anchors[i][0].tensor, expected_anchor_tensor)

def test_rrpn_anchor_generator(self):
cfg = get_cfg()
cfg.MODEL.ANCHOR_GENERATOR.SIZES = [[32, 64]]
Expand Down

0 comments on commit 273e3b9

Please sign in to comment.