Skip to content

Commit

Permalink
Coverage fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ashnair1 committed Oct 12, 2021
1 parent 7b111b4 commit 1074d6b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion tests/datasets/test_spacenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ def dataset(
)

def test_getitem(self, dataset: SpaceNet4) -> None:
x = dataset[0]
# Get image-label pair with empty label to
# enusre coverage
x = dataset[2]
assert isinstance(x, dict)
assert isinstance(x["image"], torch.Tensor)
assert isinstance(x["mask"], torch.Tensor)
Expand Down
3 changes: 2 additions & 1 deletion torchgeo/datasets/spacenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import rasterio as rio
import torch
from affine import Affine
from fiona.errors import DriverError
from rasterio.features import rasterize
from torch import Tensor

Expand Down Expand Up @@ -157,7 +158,7 @@ def _load_mask(self, path: str, tfm: Affine, shape: Tuple[int, int]) -> Tensor:
try:
with fiona.open(path) as src:
labels = [feature["geometry"] for feature in src]
except Exception:
except DriverError:
labels = []

if not labels:
Expand Down

0 comments on commit 1074d6b

Please sign in to comment.