Skip to content

Commit

Permalink
writing tests for empty frames, we will need to bump torchvision version
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Weinstein authored and Ben Weinstein committed Jul 15, 2021
1 parent 9fd7202 commit 7d6bb14
Show file tree
Hide file tree
Showing 7 changed files with 701 additions and 859 deletions.
89 changes: 0 additions & 89 deletions conda_recipe/meta.yaml

This file was deleted.

1 change: 1 addition & 0 deletions deepforest/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __getitem__(self, idx):
image = image.astype("float32")

if self.train:

# select annotations
image_annotations = self.annotations[self.annotations.image_path ==
self.image_names[idx]]
Expand Down
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sphinx_rtd_theme
sphinx_markdown_tables
tqdm
twine
torchvision
torchvision >= 0.9.0
xmltodict
comet_ml
imagecodecs
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: DeepForest
channels:
- pytorch
- conda-forge
- defaults
dependencies:
- sphinx
- recommonmark
Expand Down
1,428 changes: 661 additions & 767 deletions project.wpu

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ def test_use_bird_release(m):
boxes = m.predict_image(path=imgpath)
assert not boxes.empty

def test_train_single(m):
def test_train_empty(m, tmpdir):
empty_csv = pd.DataFrame({"image_path":"OSBS_029.png","xmin":[0],"xmax":[0],"ymin":[0],"ymax":[0],"label":["Tree"]})
empty_csv.to_csv("{}/empty.csv".format(tmpdir))
m.config["train"]["csv_file"] = "{}/empty.csv".format(tmpdir)
m.trainer.fit(m)

def test_train_single(m):
m.trainer.fit(m)

def test_train_multi(two_class_m):
two_class_m.trainer.fit(two_class_m)

Expand Down
31 changes: 31 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
import pytest
import numpy as np
import torch
import torchvision
import os

os.environ['KMP_DUPLICATE_LIB_OK']='True'

#Empty tester from https://github.com/datumbox/vision/blob/06ebee1a9f10c76d8ac5768fd578362dd5ace6e9/test/test_models_detection_negative_samples.py#L14
def _make_empty_sample():
images = [torch.rand((3, 100, 100), dtype=torch.float32)]
boxes = torch.zeros((0, 4), dtype=torch.float32)
negative_target = {"boxes": boxes,
"labels": torch.zeros(0, dtype=torch.int64),
"image_id": 4,
"area": (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0]),
"iscrowd": torch.zeros((0,), dtype=torch.int64)}

targets = [negative_target]
return images, targets

def test_load_backbone():
retinanet = model.load_backbone()
Expand All @@ -17,3 +34,17 @@ def test_create_model(num_classes):
retinanet_model.eval()
x = [torch.rand(3, 300, 400), torch.rand(3, 500, 400)]
predictions = retinanet_model(x)

def test_forward_empty():
retinanet_model = model.create_model(num_classes=2,nms_thresh=0.1, score_thresh=0.2)
image, targets = _make_empty_sample()
loss = retinanet_model(image, targets)

def test_forward_negative_sample_retinanet(self):
model = torchvision.models.detection.retinanet_resnet50_fpn(
num_classes=2, min_size=100, max_size=100)

images, targets = self._make_empty_sample()
loss_dict = model(images, targets)

self.assertEqual(loss_dict["bbox_regression"], torch.tensor(0.))

0 comments on commit 7d6bb14

Please sign in to comment.