Skip to content

Commit

Permalink
Change image readers from mmcv to cv2 in example usage and test
Browse files Browse the repository at this point in the history
  • Loading branch information
vniclas committed Jun 28, 2021
1 parent e266b40 commit fbc562a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Expand Up @@ -19,7 +19,7 @@
from pathlib import Path
from typing import Tuple, Any, Dict, Union, List

import mmcv
import cv2
import numpy as np
from PIL import Image as PilImage
from cityscapesscripts.evaluation.evalPanopticSemanticLabeling import pq_compute_multi_core, average_pq
Expand Down Expand Up @@ -213,7 +213,7 @@ def __getitem__(self, idx: int) -> Tuple[Image, None]:
:rtype: Tuple of (Image, None)
"""
image_filename = self._image_filenames[idx]
image = Image(mmcv.imread(image_filename), image_filename.name)
image = Image(cv2.imread(image_filename), image_filename.name)

return image, None

Expand Down Expand Up @@ -258,7 +258,8 @@ def prepare_data(input_path: Union[str, bytes, os.PathLike], output_path: Union[
if not (input_path / 'leftImg8bit').exists():
raise ValueError('Please download and extract the image files first: leftImg8bit_trainvaltest.zip')
if not (input_path / 'gtFine').exists():
raise ValueError('Please download and extract the ground truth fine annotations first: gtFine_trainvaltest.zip')
raise ValueError(
'Please download and extract the ground truth fine annotations first: gtFine_trainvaltest.zip')

# COCO-style category list
coco_categories = []
Expand Down
6 changes: 3 additions & 3 deletions src/opendr/perception/panoptic_segmentation/datasets/kitti.py
Expand Up @@ -20,7 +20,6 @@
from typing import Tuple, Any, Dict, Union, List, Optional

import cv2
import mmcv
import numpy as np
from PIL import Image as PilImage
from cityscapesscripts.evaluation.evalPanopticSemanticLabeling import pq_compute_multi_core, average_pq
Expand Down Expand Up @@ -215,7 +214,7 @@ def __getitem__(self, idx: int) -> Tuple[Image, None]:
:rtype: Tuple of (Image, None)
"""
image_filename = self._image_filenames[idx]
image = Image(mmcv.imread(image_filename), image_filename.name)
image = Image(cv2.imread(image_filename), image_filename.name)

return image, None

Expand Down Expand Up @@ -258,7 +257,8 @@ def prepare_data(input_path: Union[str, bytes, os.PathLike], output_path: Union[
if output_path.exists():
raise ValueError('The specified output path already exists.')
if not (input_path / 'training').exists() or not (input_path / 'validation').exists():
raise ValueError('Please download and extract the KITTI panoptic segmentation dataset first: http://panoptic.cs.uni-freiburg.de/')
raise ValueError(
'Please download and extract the KITTI panoptic segmentation dataset first: http://panoptic.cs.uni-freiburg.de/')

# COCO-style category list
coco_categories = []
Expand Down
Expand Up @@ -14,7 +14,7 @@
from pathlib import Path
from typing import List, Tuple

import mmcv
import cv2

from opendr.engine.data import Image
from opendr.engine.target import Heatmap
Expand Down Expand Up @@ -64,11 +64,11 @@ def evaluate():

def inference():
image_filenames = [
f'{CITYSCAPES_ROOT}/test/images/lindau_000001_000019.png',
f'{CITYSCAPES_ROOT}/test/images/lindau_000002_000019.png',
f'{CITYSCAPES_ROOT}/test/images/lindau_000003_000019.png',
f'{CITYSCAPES_ROOT}/val/images/lindau_000001_000019.png',
f'{CITYSCAPES_ROOT}/val/images/lindau_000002_000019.png',
f'{CITYSCAPES_ROOT}/val/images/lindau_000003_000019.png',
]
images = [Image(mmcv.imread(f)) for f in image_filenames]
images = [Image(cv2.imread(f)) for f in image_filenames]

learner = EfficientPsLearner(
device='cuda:0',
Expand Down
Expand Up @@ -18,7 +18,7 @@
import zipfile
from typing import List, Tuple

import mmcv
import cv2

from opendr.engine.data import Image
from opendr.engine.target import Heatmap
Expand Down Expand Up @@ -83,14 +83,14 @@ def test_eval(self):

def test_infer_single_image(self):
image_filename = os.path.join(self.test_data, 'infer_data', 'lindau_000001_000019.png')
image = Image(mmcv.imread(image_filename))
image = Image(cv2.imread(image_filename))
learner = EfficientPsLearner()
learner.load(self.model_weights)
prediction: Tuple[Heatmap, Heatmap] = learner.infer(image)
for heatmap in prediction:
self.assertIsInstance(heatmap, Heatmap)

image_with_filename = ImageWithFilename(mmcv.imread(image_filename), filename='lindau_000001_000019.png')
image_with_filename = ImageWithFilename(cv2.imread(image_filename), filename='lindau_000001_000019.png')
prediction: Tuple[Heatmap, Heatmap] = learner.infer(image_with_filename)
for heatmap in prediction:
self.assertIsInstance(heatmap, Heatmap)
Expand All @@ -100,7 +100,7 @@ def test_infer_batch_images(self):
os.path.join(self.test_data, 'infer_data', 'lindau_000001_000019.png'),
os.path.join(self.test_data, 'infer_data', 'lindau_000003_000019.png'),
]
images = [Image(mmcv.imread(f)) for f in image_filenames]
images = [Image(cv2.imread(f)) for f in image_filenames]
learner = EfficientPsLearner()
learner.load(self.model_weights)
predictions: List[Tuple[Heatmap, Heatmap]] = learner.infer(images)
Expand Down

0 comments on commit fbc562a

Please sign in to comment.