Unverified Commit eae81c1e authored by Kai Chen's avatar Kai Chen Committed by GitHub
Browse files

Add yapf and isort to travis (#96)

* add yapf and isort to travis

* minor formatting

* remove blank lines

* skip unit tests for progressbar when python2

* update travis to ubuntu 16.04

* use a newer version ffmpeg

* add -y to add-apt-repository
parent 3e1e297d
......@@ -3,9 +3,9 @@ from collections import OrderedDict
import cv2
from mmcv.utils import (scandir, check_file_exist, mkdir_or_exist,
track_progress)
from mmcv.opencv_info import USE_OPENCV2
from mmcv.utils import (check_file_exist, mkdir_or_exist, scandir,
track_progress)
if not USE_OPENCV2:
from cv2 import (CAP_PROP_FRAME_WIDTH, CAP_PROP_FRAME_HEIGHT, CAP_PROP_FPS,
......
import numpy as np
from mmcv.arraymisc import quantize, dequantize
from mmcv._ext import flow_warp_c
from mmcv.arraymisc import dequantize, quantize
from mmcv.image import imread, imwrite
from mmcv.utils import is_str
from mmcv._ext import flow_warp_c
def flowread(flow_or_path, quantize=False, concat_axis=0, *args, **kwargs):
......@@ -162,9 +162,10 @@ def flow_warp(img, flow, filling_value=0, interpolate_mode='nearest'):
interpolate_mode = interpolate_mode_dict[interpolate_mode]
img_float = img.astype(np.float64)
out = flow_warp_c(img_float,
flow.astype(np.float64),
filling_value=filling_value,
interpolate_mode=interpolate_mode)
out = flow_warp_c(
img_float,
flow.astype(np.float64),
filling_value=filling_value,
interpolate_mode=interpolate_mode)
return out
......@@ -2,9 +2,9 @@ from __future__ import division
import numpy as np
from .image import imshow
from mmcv.image import rgb2bgr
from mmcv.video import flowread
from .image import imshow
def flowshow(flow, win_name='', wait_time=0):
......@@ -42,8 +42,9 @@ def flow2rgb(flow, color_wheel=None, unknown_thr=1e6):
dx = flow[:, :, 0].copy()
dy = flow[:, :, 1].copy()
ignore_inds = (np.isnan(dx) | np.isnan(dy) | (np.abs(dx) > unknown_thr) |
(np.abs(dy) > unknown_thr))
ignore_inds = (
np.isnan(dx) | np.isnan(dy) | (np.abs(dx) > unknown_thr) |
(np.abs(dy) > unknown_thr))
dx[ignore_inds] = 0
dy[ignore_inds] = 0
......@@ -62,8 +63,8 @@ def flow2rgb(flow, color_wheel=None, unknown_thr=1e6):
bin_left = np.floor(bin_real).astype(int)
bin_right = (bin_left + 1) % num_bins
w = (bin_real - bin_left.astype(np.float32))[..., None]
flow_img = (
1 - w) * color_wheel[bin_left, :] + w * color_wheel[bin_right, :]
flow_img = (1 -
w) * color_wheel[bin_left, :] + w * color_wheel[bin_right, :]
small_ind = rad <= 1
flow_img[small_ind] = 1 - rad[small_ind, None] * (1 - flow_img[small_ind])
flow_img[np.logical_not(small_ind)] *= 0.75
......
......@@ -5,4 +5,17 @@ universal=1
test=pytest
[tool:pytest]
addopts=tests/
\ No newline at end of file
addopts=tests/
[yapf]
based_on_style = pep8
blank_line_before_nested_class_or_def = true
split_before_expression_after_opening_paren = true
[isort]
line_length = 79
multi_line_output = 0
known_first_party = mmcv
known_third_party = addict,cv2,matplotlib,numpy,requests,six,torch,yaml
no_lines_before = STDLIB,LOCALFOLDER
default_section = THIRDPARTY
\ No newline at end of file
from __future__ import division
import mmcv
import numpy as np
import pytest
import mmcv
def test_quantize():
arr = np.random.randn(10, 10)
......
import os.path as osp
import pytest
from mmcv import Config, FileNotFoundError
......
......@@ -2,9 +2,10 @@ import os
import os.path as osp
import tempfile
import mmcv
import pytest
import mmcv
def _test_handler(file_format, test_obj, str_checker, mode='r+'):
# dump to a string
......
......@@ -3,10 +3,11 @@ import os.path as osp
import tempfile
import cv2
import mmcv
import numpy as np
import pytest
from numpy.testing import assert_array_equal, assert_array_almost_equal
from numpy.testing import assert_array_almost_equal, assert_array_equal
import mmcv
class TestImage(object):
......@@ -57,8 +58,9 @@ class TestImage(object):
def test_bgr2gray(self):
in_img = np.random.rand(10, 10, 3).astype(np.float32)
out_img = mmcv.bgr2gray(in_img)
computed_gray = (in_img[:, :, 0] * 0.114 + in_img[:, :, 1] * 0.587 +
in_img[:, :, 2] * 0.299)
computed_gray = (
in_img[:, :, 0] * 0.114 + in_img[:, :, 1] * 0.587 +
in_img[:, :, 2] * 0.299)
assert_array_almost_equal(out_img, computed_gray, decimal=4)
out_img_3d = mmcv.bgr2gray(in_img, True)
assert out_img_3d.shape == (10, 10, 1)
......
import mmcv
import pytest
import mmcv
def test_iter_cast():
assert mmcv.list_cast([1, 2, 3], int) == [1, 2, 3]
......
......@@ -5,10 +5,11 @@ import os.path as osp
import tempfile
import time
import mmcv
import numpy as np
import pytest
from numpy.testing import assert_array_equal, assert_array_almost_equal
from numpy.testing import assert_array_almost_equal, assert_array_equal
import mmcv
def test_flowread():
......@@ -23,18 +24,18 @@ def test_flowread():
assert_array_equal(flow, flow_same)
# read quantized flow concatenated vertically
flow = mmcv.flowread(osp.join(osp.dirname(__file__),
'data/optflow_concat0.jpg'),
quantize=True,
denorm=True)
flow = mmcv.flowread(
osp.join(osp.dirname(__file__), 'data/optflow_concat0.jpg'),
quantize=True,
denorm=True)
assert flow.shape == flow_shape
# read quantized flow concatenated horizontally
flow = mmcv.flowread(osp.join(osp.dirname(__file__),
'data/optflow_concat1.jpg'),
quantize=True,
concat_axis=1,
denorm=True)
flow = mmcv.flowread(
osp.join(osp.dirname(__file__), 'data/optflow_concat1.jpg'),
quantize=True,
concat_axis=1,
denorm=True)
assert flow.shape == flow_shape
# test exceptions
......@@ -62,10 +63,8 @@ def test_flowwrite():
# write to two .jpg files
tmp_filename = osp.join(tempfile.gettempdir(), 'mmcv_test_flow.jpg')
for concat_axis in range(2):
mmcv.flowwrite(flow,
tmp_filename,
quantize=True,
concat_axis=concat_axis)
mmcv.flowwrite(
flow, tmp_filename, quantize=True, concat_axis=concat_axis)
shape = (200, 100) if concat_axis == 0 else (100, 200)
assert osp.isfile(tmp_filename)
assert mmcv.imread(tmp_filename, flag='unchanged').shape == shape
......@@ -144,6 +143,7 @@ def test_flow2rgb():
def test_flow_warp():
def np_flow_warp(flow, img):
output = np.zeros_like(img, dtype=img.dtype)
height = flow.shape[0]
......
......@@ -2,9 +2,10 @@ import os.path as osp
import sys
from pathlib import Path
import mmcv
import pytest
import mmcv
def test_is_filepath():
assert mmcv.is_filepath(__file__)
......
import sys
import time
import pytest
import mmcv
if sys.version_info[0] == 2:
pytest.skip('skipping tests for python 2', allow_module_level=True)
class TestProgressBar(object):
......
......@@ -14,10 +14,7 @@ def test_save_checkpoint():
import mmcv.runner
model = nn.Linear(1, 1)
runner = mmcv.runner.Runner(
model=model,
batch_processor=lambda x: x
)
runner = mmcv.runner.Runner(model=model, batch_processor=lambda x: x)
with tempfile.TemporaryDirectory() as root:
runner.save_checkpoint(root)
......
import time
import mmcv
import pytest
import mmcv
def test_timer_init():
timer = mmcv.Timer(start=False)
......
......@@ -3,9 +3,10 @@ import os.path as osp
import tempfile
from collections import OrderedDict
import mmcv
import pytest
import mmcv
class TestCache(object):
......
import mmcv
import numpy as np
import pytest
import mmcv
def test_color():
assert mmcv.color_val(mmcv.Color.blue) == (255, 0, 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment