Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
ddef9a56
"vscode:/vscode.git/clone" did not exist on "57fde871e117090fc766cc36caddf605f7c72465"
Commit
ddef9a56
authored
Oct 01, 2018
by
Kai Chen
Browse files
fix flake8 errors
parent
f9d8870f
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
165 additions
and
86 deletions
+165
-86
mmcv/__init__.py
mmcv/__init__.py
+1
-0
mmcv/arraymisc/__init__.py
mmcv/arraymisc/__init__.py
+3
-1
mmcv/arraymisc/quantization.py
mmcv/arraymisc/quantization.py
+0
-2
mmcv/image/__init__.py
mmcv/image/__init__.py
+12
-2
mmcv/image/io.py
mmcv/image/io.py
+0
-2
mmcv/image/transforms/__init__.py
mmcv/image/transforms/__init__.py
+11
-4
mmcv/image/transforms/colorspace.py
mmcv/image/transforms/colorspace.py
+0
-2
mmcv/image/transforms/geometry.py
mmcv/image/transforms/geometry.py
+0
-2
mmcv/image/transforms/normalize.py
mmcv/image/transforms/normalize.py
+0
-2
mmcv/torchpack/__init__.py
mmcv/torchpack/__init__.py
+19
-5
mmcv/torchpack/runner/__init__.py
mmcv/torchpack/runner/__init__.py
+2
-0
mmcv/utils/__init__.py
mmcv/utils/__init__.py
+17
-5
mmcv/utils/misc.py
mmcv/utils/misc.py
+48
-27
mmcv/utils/timer.py
mmcv/utils/timer.py
+2
-0
mmcv/video/__init__.py
mmcv/video/__init__.py
+8
-17
mmcv/video/io.py
mmcv/video/io.py
+27
-10
mmcv/video/processing.py
mmcv/video/processing.py
+4
-1
mmcv/visualization/__init__.py
mmcv/visualization/__init__.py
+8
-3
mmcv/visualization/color.py
mmcv/visualization/color.py
+1
-1
tests/test_optflow.py
tests/test_optflow.py
+2
-0
No files found.
mmcv/__init__.py
View file @
ddef9a56
# flake8: noqa
from
.arraymisc
import
*
from
.utils
import
*
from
.fileio
import
*
...
...
mmcv/arraymisc/__init__.py
View file @
ddef9a56
from
.quantization
import
*
from
.quantization
import
quantize
,
dequantize
__all__
=
[
'quantize'
,
'dequantize'
]
mmcv/arraymisc/quantization.py
View file @
ddef9a56
import
numpy
as
np
__all__
=
[
'quantize'
,
'dequantize'
]
def
quantize
(
arr
,
min_val
,
max_val
,
levels
,
dtype
=
np
.
int64
):
"""Quantize an array of (-inf, inf) to [0, levels-1].
...
...
mmcv/image/__init__.py
View file @
ddef9a56
from
.io
import
*
from
.transforms
import
*
from
.io
import
imread
,
imwrite
,
imfrombytes
from
.transforms
import
(
bgr2gray
,
gray2bgr
,
bgr2rgb
,
rgb2bgr
,
bgr2hsv
,
hsv2bgr
,
imflip
,
imrotate
,
imcrop
,
impad
,
impad_to_multiple
,
imnorm
,
imdenorm
,
scale_size
,
imresize
,
imresize_like
,
imrescale
,
limit_size
)
__all__
=
[
'imread'
,
'imwrite'
,
'imfrombytes'
,
'bgr2gray'
,
'gray2bgr'
,
'bgr2rgb'
,
'rgb2bgr'
,
'bgr2hsv'
,
'hsv2bgr'
,
'imflip'
,
'imrotate'
,
'imcrop'
,
'impad'
,
'impad_to_multiple'
,
'imnorm'
,
'imdenorm'
,
'scale_size'
,
'imresize'
,
'imresize_like'
,
'imrescale'
,
'limit_size'
]
mmcv/image/io.py
View file @
ddef9a56
...
...
@@ -19,8 +19,6 @@ imread_flags = {
'unchanged'
:
IMREAD_UNCHANGED
}
__all__
=
[
'imread'
,
'imwrite'
,
'imfrombytes'
]
def
imread
(
img_or_path
,
flag
=
'color'
):
"""Read an image.
...
...
mmcv/image/transforms/__init__.py
View file @
ddef9a56
from
.colorspace
import
*
from
.geometry
import
*
from
.normalize
import
*
from
.resize
import
*
from
.colorspace
import
bgr2gray
,
gray2bgr
,
bgr2rgb
,
rgb2bgr
,
bgr2hsv
,
hsv2bgr
from
.geometry
import
imflip
,
imrotate
,
imcrop
,
impad
,
impad_to_multiple
from
.normalize
import
imnorm
,
imdenorm
from
.resize
import
scale_size
,
imresize
,
imresize_like
,
imrescale
,
limit_size
__all__
=
[
'bgr2gray'
,
'gray2bgr'
,
'bgr2rgb'
,
'rgb2bgr'
,
'bgr2hsv'
,
'hsv2bgr'
,
'imflip'
,
'imrotate'
,
'imcrop'
,
'impad'
,
'impad_to_multiple'
,
'imnorm'
,
'imdenorm'
,
'scale_size'
,
'imresize'
,
'imresize_like'
,
'imrescale'
,
'limit_size'
]
mmcv/image/transforms/colorspace.py
View file @
ddef9a56
import
cv2
__all__
=
[
'bgr2gray'
,
'gray2bgr'
,
'bgr2rgb'
,
'rgb2bgr'
,
'bgr2hsv'
,
'hsv2bgr'
]
def
bgr2gray
(
img
,
keepdim
=
False
):
"""Convert a BGR image to grayscale image.
...
...
mmcv/image/transforms/geometry.py
View file @
ddef9a56
...
...
@@ -3,8 +3,6 @@ from __future__ import division
import
cv2
import
numpy
as
np
__all__
=
[
'imflip'
,
'imrotate'
,
'imcrop'
,
'impad'
,
'impad_to_multiple'
]
def
imflip
(
img
,
direction
=
'horizontal'
):
"""Flip an image horizontally or vertically.
...
...
mmcv/image/transforms/normalize.py
View file @
ddef9a56
...
...
@@ -2,8 +2,6 @@ import numpy as np
from
.colorspace
import
bgr2rgb
,
rgb2bgr
__all__
=
[
'imnorm'
,
'imdenorm'
]
def
imnorm
(
img
,
mean
,
std
,
to_rgb
=
True
):
img
=
img
.
astype
(
np
.
float32
)
...
...
mmcv/torchpack/__init__.py
View file @
ddef9a56
from
.hooks
import
*
from
.io
import
*
from
.parallel
import
*
from
.runner
import
*
from
.utils
import
*
from
.runner
import
Runner
,
LogBuffer
from
.hooks
import
(
Hook
,
CheckpointHook
,
ClosureHook
,
LrUpdaterHook
,
OptimizerHook
,
IterTimerHook
,
DistSamplerSeedHook
,
LoggerHook
,
TextLoggerHook
,
PaviLoggerHook
,
TensorboardLoggerHook
)
from
.io
import
(
load_state_dict
,
load_checkpoint
,
weights_to_cpu
,
save_checkpoint
)
from
.parallel
import
parallel_test
,
worker_func
from
.utils
import
(
get_host_info
,
get_dist_info
,
master_only
,
get_time_str
,
add_file_handler
,
obj_from_dict
)
__all__
=
[
'Runner'
,
'LogBuffer'
,
'Hook'
,
'CheckpointHook'
,
'ClosureHook'
,
'LrUpdaterHook'
,
'OptimizerHook'
,
'IterTimerHook'
,
'DistSamplerSeedHook'
,
'LoggerHook'
,
'TextLoggerHook'
,
'PaviLoggerHook'
,
'TensorboardLoggerHook'
,
'load_state_dict'
,
'load_checkpoint'
,
'weights_to_cpu'
,
'save_checkpoint'
,
'parallel_test'
,
'worker_func'
,
'get_host_info'
,
'get_dist_info'
,
'master_only'
,
'get_time_str'
,
'add_file_handler'
,
'obj_from_dict'
]
mmcv/torchpack/runner/__init__.py
View file @
ddef9a56
from
.log_buffer
import
LogBuffer
from
.runner
import
Runner
__all__
=
[
'LogBuffer'
,
'Runner'
]
mmcv/utils/__init__.py
View file @
ddef9a56
from
.config
import
*
from
.misc
import
*
from
.path
import
*
from
.progressbar
import
*
from
.timer
import
*
from
.config
import
ConfigDict
,
Config
from
.misc
import
(
is_str
,
iter_cast
,
list_cast
,
tuple_cast
,
is_seq_of
,
is_list_of
,
is_tuple_of
,
slice_list
,
concat_list
,
check_prerequisites
,
requires_package
,
requires_executable
)
from
.path
import
(
is_filepath
,
fopen
,
check_file_exist
,
mkdir_or_exist
,
symlink
,
scandir
)
from
.progressbar
import
ProgressBar
,
track_progress
,
track_parallel_progress
from
.timer
import
Timer
,
TimerError
,
check_time
__all__
=
[
'ConfigDict'
,
'Config'
,
'is_str'
,
'iter_cast'
,
'list_cast'
,
'tuple_cast'
,
'is_seq_of'
,
'is_list_of'
,
'is_tuple_of'
,
'slice_list'
,
'concat_list'
,
'check_prerequisites'
,
'requires_package'
,
'requires_executable'
,
'is_filepath'
,
'fopen'
,
'check_file_exist'
,
'mkdir_or_exist'
,
'symlink'
,
'scandir'
,
'ProgressBar'
,
'track_progress'
,
'track_parallel_progress'
,
'Timer'
,
'TimerError'
,
'check_time'
]
mmcv/utils/misc.py
View file @
ddef9a56
...
...
@@ -37,9 +37,20 @@ def iter_cast(inputs, dst_type, return_type=None):
return
return_type
(
out_iterable
)
list_cast
=
functools
.
partial
(
iter_cast
,
return_type
=
list
)
def
list_cast
(
inputs
,
dst_type
):
"""Cast elements of an iterable object into a list of some type.
A partial method of :func:`iter_cast`.
"""
return
iter_cast
(
inputs
,
dst_type
,
return_type
=
list
)
tuple_cast
=
functools
.
partial
(
iter_cast
,
return_type
=
tuple
)
def
tuple_cast
(
inputs
,
dst_type
):
"""Cast elements of an iterable object into a tuple of some type.
A partial method of :func:`iter_cast`.
"""
return
iter_cast
(
inputs
,
dst_type
,
return_type
=
tuple
)
def
is_seq_of
(
seq
,
expected_type
,
seq_type
=
None
):
...
...
@@ -66,9 +77,20 @@ def is_seq_of(seq, expected_type, seq_type=None):
return
True
is_list_of
=
functools
.
partial
(
is_seq_of
,
seq_type
=
list
)
def
is_list_of
(
seq
,
expected_type
):
"""Check whether it is a list of some type.
A partial method of :func:`is_seq_of`.
"""
return
is_seq_of
(
seq
,
expected_type
,
seq_type
=
list
)
is_tuple_of
=
functools
.
partial
(
is_seq_of
,
seq_type
=
tuple
)
def
is_tuple_of
(
seq
,
expected_type
):
"""Check whether it is a tuple of some type.
A partial method of :func:`is_seq_of`.
"""
return
is_seq_of
(
seq
,
expected_type
,
seq_type
=
tuple
)
def
slice_list
(
in_list
,
lens
):
...
...
@@ -161,12 +183,10 @@ def _check_executable(cmd):
return
True
requires_package
=
functools
.
partial
(
check_prerequisites
,
checker
=
_check_py_package
)
def
requires_package
(
prerequisites
):
"""A decorator to check if some python packages are installed.
requires_package
.
__doc__
=
"""A decorator to check if some python packages are installed.
Example:
Example:
>>> @requires_package('numpy')
>>> func(arg1, args):
>>> return numpy.zeros(1)
...
...
@@ -175,16 +195,17 @@ Example:
>>> func(arg1, args):
>>> return numpy.zeros(1)
ImportError
"""
"""
return
check_prerequisites
(
prerequisites
,
checker
=
_check_py_package
)
requires_executable
=
functools
.
partial
(
check_prerequisites
,
checker
=
_check_executable
)
requires_executable
.
__doc__
=
"""A decorator to check if some executable files are installed.
def
requires_executable
(
prerequisites
):
"""A decorator to check if some executable files are installed.
Example:
Example:
>>> @requires_executable('ffmpeg')
>>> func(arg1, args):
>>> print(1)
1
"""
"""
return
check_prerequisites
(
prerequisites
,
checker
=
_check_executable
)
mmcv/utils/timer.py
View file @
ddef9a56
...
...
@@ -12,6 +12,7 @@ class Timer(object):
"""A flexible Timer class.
:Example:
>>> import time
>>> import mmcv
>>> with mmcv.Timer():
...
...
@@ -94,6 +95,7 @@ def check_time(timer_id):
be registered when the method is called for the first time.
:Example:
>>> import time
>>> import mmcv
>>> for i in range(1, 6):
...
...
mmcv/video/__init__.py
View file @
ddef9a56
from
mmcv.opencv_info
import
USE_OPENCV2
from
.io
import
Cache
,
VideoReader
,
frames2video
from
.processing
import
convert_video
,
resize_video
,
cut_video
,
concat_video
from
.optflow
import
flowread
,
flowwrite
,
quantize_flow
,
dequantize_flow
if
not
USE_OPENCV2
:
from
cv2
import
(
CAP_PROP_FRAME_WIDTH
,
CAP_PROP_FRAME_HEIGHT
,
CAP_PROP_FPS
,
CAP_PROP_FRAME_COUNT
,
CAP_PROP_FOURCC
,
CAP_PROP_POS_FRAMES
,
VideoWriter_fourcc
)
else
:
from
cv2.cv
import
CV_CAP_PROP_FRAME_WIDTH
as
CAP_PROP_FRAME_WIDTH
from
cv2.cv
import
CV_CAP_PROP_FRAME_HEIGHT
as
CAP_PROP_FRAME_HEIGHT
from
cv2.cv
import
CV_CAP_PROP_FPS
as
CAP_PROP_FPS
from
cv2.cv
import
CV_CAP_PROP_FRAME_COUNT
as
CAP_PROP_FRAME_COUNT
from
cv2.cv
import
CV_CAP_PROP_FOURCC
as
CAP_PROP_FOURCC
from
cv2.cv
import
CV_CAP_PROP_POS_FRAMES
as
CAP_PROP_POS_FRAMES
from
cv2.cv
import
CV_FOURCC
as
VideoWriter_fourcc
from
.io
import
*
from
.processing
import
*
from
.optflow
import
*
__all__
=
[
'Cache'
,
'VideoReader'
,
'frames2video'
,
'convert_video'
,
'resize_video'
,
'cut_video'
,
'concat_video'
,
'flowread'
,
'flowwrite'
,
'quantize_flow'
,
'dequantize_flow'
]
mmcv/video/io.py
View file @
ddef9a56
from
collections
import
OrderedDict
import
os.path
as
osp
from
collections
import
OrderedDict
import
cv2
from
mmcv.utils
import
(
scandir
,
check_file_exist
,
mkdir_or_exist
,
track_progress
)
from
.
import
(
CAP_PROP_FRAME_WIDTH
,
CAP_PROP_FRAME_HEIGHT
,
CAP_PROP_FPS
,
CAP_PROP_FRAME_COUNT
,
CAP_PROP_FOURCC
,
CAP_PROP_POS_FRAMES
,
VideoWriter_fourcc
)
from
mmcv.opencv_info
import
USE_OPENCV2
if
not
USE_OPENCV2
:
from
cv2
import
(
CAP_PROP_FRAME_WIDTH
,
CAP_PROP_FRAME_HEIGHT
,
CAP_PROP_FPS
,
CAP_PROP_FRAME_COUNT
,
CAP_PROP_FOURCC
,
CAP_PROP_POS_FRAMES
,
VideoWriter_fourcc
)
else
:
from
cv2.cv
import
CV_CAP_PROP_FRAME_WIDTH
as
CAP_PROP_FRAME_WIDTH
from
cv2.cv
import
CV_CAP_PROP_FRAME_HEIGHT
as
CAP_PROP_FRAME_HEIGHT
from
cv2.cv
import
CV_CAP_PROP_FPS
as
CAP_PROP_FPS
from
cv2.cv
import
CV_CAP_PROP_FRAME_COUNT
as
CAP_PROP_FRAME_COUNT
from
cv2.cv
import
CV_CAP_PROP_FOURCC
as
CAP_PROP_FOURCC
from
cv2.cv
import
CV_CAP_PROP_POS_FRAMES
as
CAP_PROP_POS_FRAMES
from
cv2.cv
import
CV_FOURCC
as
VideoWriter_fourcc
class
Cache
(
object
):
...
...
@@ -50,6 +61,7 @@ class VideoReader(object):
cache.
:Example:
>>> import mmcv
>>> v = mmcv.VideoReader('sample.mp4')
>>> len(v) # get the total frame number with `len()`
...
...
@@ -131,7 +143,7 @@ class VideoReader(object):
"""Read the next frame.
If the next frame have been decoded before and in the cache, then
return it directly, otherwise decode and return it
, put it in the cache
.
return it directly, otherwise decode
, cache
and return it.
Returns:
ndarray or None: Return the frame if successful, otherwise None.
...
...
@@ -163,8 +175,9 @@ class VideoReader(object):
ndarray or None: Return the frame if successful, otherwise None.
"""
if
frame_id
<
0
or
frame_id
>=
self
.
_frame_cnt
:
raise
IndexError
(
'"frame_id" must be between 0 and {}'
.
format
(
self
.
_frame_cnt
-
1
))
raise
IndexError
(
'"frame_id" must be between 0 and {}'
.
format
(
self
.
_frame_cnt
-
1
))
if
frame_id
==
self
.
_position
:
return
self
.
read
()
if
self
.
_cache
:
...
...
@@ -203,7 +216,8 @@ class VideoReader(object):
Args:
frame_dir (str): Output directory to store all the frame images.
file_start (int): Filenames will start from the specified number.
filename_tmpl (str): Filename template with the index as the variable.
filename_tmpl (str): Filename template with the index as the
placeholder.
start (int): The starting frame index.
max_num (int): Maximum number of frames to be written.
show_progress (bool): Whether to show a progress bar.
...
...
@@ -240,7 +254,10 @@ class VideoReader(object):
def
__getitem__
(
self
,
index
):
if
isinstance
(
index
,
slice
):
return
[
self
.
get_frame
(
i
)
for
i
in
range
(
*
index
.
indices
(
self
.
frame_cnt
))]
return
[
self
.
get_frame
(
i
)
for
i
in
range
(
*
index
.
indices
(
self
.
frame_cnt
))
]
# support negative indexing
if
index
<
0
:
index
+=
self
.
frame_cnt
...
...
mmcv/video/processing.py
View file @
ddef9a56
...
...
@@ -12,8 +12,11 @@ def convert_video(in_file, out_file, print_cmd=False, pre_options='',
"""Convert a video with ffmpeg.
This provides a general api to ffmpeg, the executed command is::
ffmpeg -y <pre_options> -i <in_file> <options> <out_file>
`ffmpeg -y <pre_options> -i <in_file> <options> <out_file>`
Options(kwargs) are mapped to ffmpeg commands with the following rules:
- key=val: "-key val"
- key=True: "-key"
- key=False: ""
...
...
mmcv/visualization/__init__.py
View file @
ddef9a56
from
.color
import
*
from
.image
import
*
from
.optflow
import
*
from
.color
import
Color
,
color_val
from
.image
import
imshow
,
imshow_bboxes
from
.optflow
import
flowshow
,
flow2rgb
,
make_color_wheel
__all__
=
[
'Color'
,
'color_val'
,
'imshow'
,
'imshow_bboxes'
,
'flowshow'
,
'flow2rgb'
,
'make_color_wheel'
]
mmcv/visualization/color.py
View file @
ddef9a56
...
...
@@ -27,7 +27,7 @@ def color_val(color):
color (:obj:`Color`/str/tuple/int/ndarray): Color inputs
Returns:
tuple: A tuple of 3 integers indicating BGR channels.
tuple
[int]
: A tuple of 3 integers indicating BGR channels.
"""
if
is_str
(
color
):
return
Color
[
color
].
value
...
...
tests/test_optflow.py
View file @
ddef9a56
# flake8: noqa
import
os
import
os.path
as
osp
import
tempfile
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment