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
6d623cf1
Commit
6d623cf1
authored
Oct 06, 2018
by
Kai Chen
Browse files
add some documentation
parent
509d12f9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
168 additions
and
49 deletions
+168
-49
docs/image.md
docs/image.md
+74
-24
docs/intro.md
docs/intro.md
+2
-2
docs/io.md
docs/io.md
+67
-18
docs/utils.md
docs/utils.md
+1
-1
mmcv/runner/priority.py
mmcv/runner/priority.py
+24
-4
No files found.
docs/image.md
View file @
6d623cf1
## Image
## Image
This module provides some image processing methods.
This module provides some image processing methods, which requires
`opencv`
to
to be installed.
### Read/Write/Show
### Read/Write/Show
To read or write images files, use
`imread`
or
`imwrite`
.
To read or write images files, use
`imread`
or
`imwrite`
.
...
@@ -26,16 +27,33 @@ To show an image file or a loaded image
...
@@ -26,16 +27,33 @@ To show an image file or a loaded image
```
python
```
python
mmcv
.
imshow
(
'tests/data/color.jpg'
)
mmcv
.
imshow
(
'tests/data/color.jpg'
)
# this is equivalent to
for
i
in
range
(
10
):
for
i
in
range
(
10
):
img
=
np
.
random
.
randint
(
256
,
size
=
(
100
,
100
,
3
),
dtype
=
np
.
uint8
)
img
=
np
.
random
.
randint
(
256
,
size
=
(
100
,
100
,
3
),
dtype
=
np
.
uint8
)
mmcv
.
imshow
(
img
,
win_name
=
'test image'
,
wait_time
=
200
)
mmcv
.
imshow
(
img
,
win_name
=
'test image'
,
wait_time
=
200
)
```
```
### Color space conversion
Supported conversion methods:
-
bgr2gray
-
gray2bgr
-
bgr2rgb
-
rgb2bgr
-
bgr2hsv
-
hsv2bgr
```
python
img
=
mmcv
.
imread
(
'tests/data/color.jpg'
)
img1
=
mmcv
.
bgr2rgb
(
img
)
img2
=
mmcv
.
rgb2gray
(
img1
)
img3
=
mmcv
.
bgr2hsv
(
img
)
```
### Resize
### Resize
There are three resize methods. All
`imresize_*`
methods have a
parameter
`return_scale`
,
There are three resize methods. All
`imresize_*`
methods have a
n argument
`return_scale`
,
if this
p
ar
am
is
`False`
, then the return value is merely the resized image, otherwise
if this ar
gument
is
`False`
, then the return value is merely the resized image, otherwise
is a tuple (resized_img, scale).
is a tuple
`
(resized_img, scale)
`
.
```
python
```
python
# resize to a given size
# resize to a given size
...
@@ -52,47 +70,79 @@ mmcv.imrescale(img, 0.5)
...
@@ -52,47 +70,79 @@ mmcv.imrescale(img, 0.5)
mmcv
.
imrescale
(
img
,
(
1000
,
800
))
mmcv
.
imrescale
(
img
,
(
1000
,
800
))
```
```
### Color space conversion
### Rotate
Supported conversion methods:
To rotate an image by some angle, use
`imrotate`
. The center can be specified,
-
bgr2gray
which is the center of original image by default. There are two modes of rotating,
-
gray2bgr
one is to keep the image size unchanged so that some parts of the image will be
-
bgr2rgb
cropped after rotating, the other is to extend the image size to fit the rotated
-
rgb2bgr
image.
-
bgr2hsv
-
hsv2bgr
```
python
```
python
img
=
mmcv
.
imread
(
'tests/data/color.jpg'
)
img
=
mmcv
.
imread
(
'tests/data/color.jpg'
)
img1
=
mmcv
.
bgr2rgb
(
img
)
img2
=
mmcv
.
rgb2gray
(
img1
)
# rotate the image clockwise by 30 degrees.
img3
=
mmcv
.
bgr2hsv
(
img
)
img_
=
mmcv
.
imrotate
(
img
,
30
)
# rotate the image counterclockwise by 90 degrees.
img_
=
mmcv
.
imrotate
(
img
,
-
90
)
# rotate the image clockwise by 30 degrees, and rescale it by 1.5x at the same time.
img_
=
mmcv
.
imrotate
(
img
,
30
,
scale
=
1.5
)
# rotate the image clockwise by 30 degrees, with (100, 100) as the center.
img_
=
mmcv
.
imrotate
(
img
,
30
,
center
=
(
100
,
100
))
# rotate the image clockwise by 30 degrees, and extend the image size.
img_
=
mmcv
.
imrotate
(
img
,
30
,
auto_bound
=
True
)
```
### Flip
To flip an image, use
`imflip`
.
```
python
img
=
mmcv
.
imread
(
'tests/data/color.jpg'
)
# flip the image horizontally
mmcv
.
imflip
(
img
)
# flip the image vertically
mmcv
.
imflip
(
img
,
direction
=
'vertical'
)
```
```
### Crop
### Crop
Support single/multiple crop
.
`imcrop`
can crop the image with one or some regions, represented as (x1, y1, x2, y2)
.
```
python
```
python
import
mmcv
import
mmcv
import
numpy
as
np
import
numpy
as
np
img
=
mmcv
.
read_img
(
'tests/data/color.jpg'
)
img
=
mmcv
.
read_img
(
'tests/data/color.jpg'
)
bboxes
=
np
.
array
([
10
,
10
,
100
,
120
])
# x1, y1, x2, y2
# crop the region (10, 10, 100, 120)
bboxes
=
np
.
array
([
10
,
10
,
100
,
120
])
patch
=
mmcv
.
crop_img
(
img
,
bboxes
)
patch
=
mmcv
.
crop_img
(
img
,
bboxes
)
# crop two regions (10, 10, 100, 120) and (0, 0, 50, 50)
bboxes
=
np
.
array
([[
10
,
10
,
100
,
120
],
[
0
,
0
,
50
,
50
]])
bboxes
=
np
.
array
([[
10
,
10
,
100
,
120
],
[
0
,
0
,
50
,
50
]])
patches
=
mmcv
.
crop_img
(
img
,
bboxes
)
patches
=
mmcv
.
crop_img
(
img
,
bboxes
)
```
Resizing cropped patches.
# crop two regions, and rescale the patches by 1.2x
```
python
# upsample patches by 1.2x
patches
=
mmcv
.
crop_img
(
img
,
bboxes
,
scale_ratio
=
1.2
)
patches
=
mmcv
.
crop_img
(
img
,
bboxes
,
scale_ratio
=
1.2
)
```
```
### Padding
### Padding
Pad an image to specific size with given values.
There are two methods
`impad`
and
`impad_to_multiple`
to pad an image to the
specific size with given values.
```
python
```
python
img
=
mmcv
.
read_img
(
'tests/data/color.jpg'
)
img
=
mmcv
.
read_img
(
'tests/data/color.jpg'
)
img
=
mmcv
.
pad_img
(
img
,
(
1000
,
1200
),
pad_val
=
0
)
img
=
mmcv
.
pad_img
(
img
,
(
1000
,
1200
),
pad_val
=
[
100
,
50
,
200
])
# pad the image to (1000, 1200) with all zeros
img_
=
mmcv
.
pad_img
(
img
,
(
1000
,
1200
),
pad_val
=
0
)
# pad the image to (1000, 1200) with different values for three channels.
img_
=
mmcv
.
pad_img
(
img
,
(
1000
,
1200
),
pad_val
=
[
100
,
50
,
200
])
# pad an image so that each edge is a multiple of some value.
img_
=
mmcv
.
impad_to_multiple
(
img
,
32
)
```
```
\ No newline at end of file
docs/intro.md
View file @
6d623cf1
# Introduction
#
# Introduction
`mmcv`
is a foundational python library for computer vision research and supports many
`mmcv`
is a foundational python library for computer vision research and supports many
research projects in MMLAB, such as
[
mmdetection
](
https://github.com/open-mmlab/mmdetection
)
.
research projects in MMLAB, such as
[
mmdetection
](
https://github.com/open-mmlab/mmdetection
)
.
...
@@ -16,7 +16,7 @@ It provides the following functionalities.
...
@@ -16,7 +16,7 @@ It provides the following functionalities.
See the
[
documentation
](
http://mmcv.readthedocs.io/en/latest
)
for more features and usage.
See the
[
documentation
](
http://mmcv.readthedocs.io/en/latest
)
for more features and usage.
## Installation
##
#
Installation
Try and start with
Try and start with
...
...
docs/io.md
View file @
6d623cf1
...
@@ -12,20 +12,73 @@ import mmcv
...
@@ -12,20 +12,73 @@ import mmcv
# load data from a file
# load data from a file
data
=
mmcv
.
load
(
'test.json'
)
data
=
mmcv
.
load
(
'test.json'
)
data
=
mmcv
.
load
(
'test.yaml'
)
data
=
mmcv
.
load
(
'test.yaml'
)
data
=
mmcv
.
load
(
'test.p
ic
kl
e
'
)
data
=
mmcv
.
load
(
'test.pkl'
)
# load data from a file-like object
# load data from a file-like object
with
open
(
'test.json'
,
'r'
)
as
f
:
with
open
(
'test.json'
,
'r'
)
as
f
:
data
=
mmcv
.
load
(
f
)
data
=
mmcv
.
load
(
f
)
# dump data to a string
# dump data to a string
json_str
=
mmcv
.
dump
(
data
,
format
=
'json'
)
json_str
=
mmcv
.
dump
(
data
,
format
=
'json'
)
# dump data to a file with a filename (infer format from file extension)
# dump data to a file with a filename (infer format from file extension)
mmcv
.
dump
(
data
,
'out.pickle'
)
mmcv
.
dump
(
data
,
'out.pkl'
)
# dump data to a file with a file-like object
# dump data to a file with a file-like object
with
open
(
'test.yaml'
,
'w'
)
as
f
:
with
open
(
'test.yaml'
,
'w'
)
as
f
:
data
=
mmcv
.
dump
(
data
,
f
,
format
=
'yaml'
)
data
=
mmcv
.
dump
(
data
,
f
,
format
=
'yaml'
)
```
```
It is also very convenient to extend the api to support more file formats.
All you need to do is to write a file handler inherited from
`BaseFileHandler`
and register it with one or several file formats.
You need to implement at least 3 methods.
```
python
import
mmcv
# To register multiple file formats, a list can be used as the argument.
# @mmcv.register_handler(['txt', 'log'])
@
mmcv
.
register_handler
(
'txt'
)
class
TxtHandler1
(
mmcv
.
BaseFileHandler
):
def
load_from_fileobj
(
self
,
file
):
return
file
.
read
()
def
dump_to_fileobj
(
self
,
obj
,
file
):
file
.
write
(
str
(
obj
))
def
dump_to_str
(
self
,
obj
,
**
kwargs
):
return
str
(
obj
)
```
Here is an example of
`PickleHandler`
.
```
python
from
six.moves
import
cPickle
as
pickle
class
PickleHandler
(
mmcv
.
BaseFileHandler
):
def
load_from_fileobj
(
self
,
file
,
**
kwargs
):
return
pickle
.
load
(
file
,
**
kwargs
)
def
load_from_path
(
self
,
filepath
,
**
kwargs
):
return
super
(
PickleHandler
,
self
).
load_from_path
(
filepath
,
mode
=
'rb'
,
**
kwargs
)
def
dump_to_str
(
self
,
obj
,
**
kwargs
):
kwargs
.
setdefault
(
'protocol'
,
2
)
return
pickle
.
dumps
(
obj
,
**
kwargs
)
def
dump_to_fileobj
(
self
,
obj
,
file
,
**
kwargs
):
kwargs
.
setdefault
(
'protocol'
,
2
)
pickle
.
dump
(
obj
,
file
,
**
kwargs
)
def
dump_to_path
(
self
,
obj
,
filepath
,
**
kwargs
):
super
(
PickleHandler
,
self
).
dump_to_path
(
obj
,
filepath
,
mode
=
'wb'
,
**
kwargs
)
```
### Load a text file as a list or dict
### Load a text file as a list or dict
For example
`a.txt`
is a text file with 5 lines.
For example
`a.txt`
is a text file with 5 lines.
...
@@ -40,16 +93,14 @@ e
...
@@ -40,16 +93,14 @@ e
Then use
`list_from_file`
to load the list from a.txt.
Then use
`list_from_file`
to load the list from a.txt.
```
python
```
python
import
mmcv
>>>
mmcv
.
list_from_file
(
'a.txt'
)
[
'a'
,
'b'
,
'c'
,
'd'
,
'e'
]
mmcv
.
list_from_file
(
'a.txt'
)
>>>
mmcv
.
list_from_file
(
'a.txt'
,
offset
=
2
)
# output ['a', 'b', 'c', 'd', 'e']
[
'c'
,
'd'
,
'e'
]
mmcv
.
list_from_file
(
'a.txt'
,
offset
=
2
)
>>>
mmcv
.
list_from_file
(
'a.txt'
,
max_num
=
2
)
# output ['c', 'd', 'e']
[
'a'
,
'b'
]
mmcv
.
list_from_file
(
'a.txt'
,
max_num
=
2
)
>>>
mmcv
.
list_from_file
(
'a.txt'
,
prefix
=
'/mnt/'
)
# output ['a', 'b']
[
'/mnt/a'
,
'/mnt/b'
,
'/mnt/c'
,
'/mnt/d'
,
'/mnt/e'
]
mmcv
.
list_from_file
(
'a.txt'
,
prefix
=
'/mnt/'
)
# output ['/mnt/a', '/mnt/b', '/mnt/c', '/mnt/d', '/mnt/e']
```
```
For example
`b.txt`
is a text file with 5 lines.
For example
`b.txt`
is a text file with 5 lines.
...
@@ -62,10 +113,8 @@ For example `b.txt` is a text file with 5 lines.
...
@@ -62,10 +113,8 @@ For example `b.txt` is a text file with 5 lines.
Then use
`dict_from_file`
to load the list from a.txt.
Then use
`dict_from_file`
to load the list from a.txt.
```
python
```
python
import
mmcv
>>>
mmcv
.
dict_from_file
(
'b.txt'
)
{
'1'
:
'cat'
,
'2'
:
[
'dog'
,
'cow'
],
'3'
:
'panda'
}
mmcv
.
dict_from_file
(
'b.txt'
)
>>>
mmcv
.
dict_from_file
(
'b.txt'
,
key_type
=
int
)
# output {'1': 'cat', '2': ['dog', 'cow'], '3': 'panda'}
{
1
:
'cat'
,
2
:
[
'dog'
,
'cow'
],
3
:
'panda'
}
mmcv
.
dict_from_file
(
'b.txt'
,
key_type
=
int
)
# output {1: 'cat', 2: ['dog', 'cow'], 3: 'panda'}
```
```
docs/utils.md
View file @
6d623cf1
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
### Config
### Config
`Config`
class is used for manipulating config and config files. It supports
`Config`
class is used for manipulating config and config files. It supports
loading configs from multiple file formats including python
scripts, json file
and yaml
file
.
loading configs from multiple file formats including
**
python
**
,
**json**
and
**
yaml
**
.
It provides dict-like apis to get and set values.
It provides dict-like apis to get and set values.
Here is an example of the config file
`test.py`
.
Here is an example of the config file
`test.py`
.
...
...
mmcv/runner/priority.py
View file @
6d623cf1
...
@@ -2,13 +2,33 @@ from enum import Enum
...
@@ -2,13 +2,33 @@ from enum import Enum
class
Priority
(
Enum
):
class
Priority
(
Enum
):
"""Hook priority levels.
+------------+------------+
| Level | Value |
+============+============+
| HIGHEST | 0 |
+------------+------------+
| VERY_HIGH | 10 |
+------------+------------+
| HIGH | 30 |
+------------+------------+
| NORMAL | 50 |
+------------+------------+
| LOW | 70 |
+------------+------------+
| VERY_LOW | 90 |
+------------+------------+
| LOWEST | 100 |
+------------+------------+
"""
HIGHEST
=
0
HIGHEST
=
0
VERY_HIGH
=
2
0
VERY_HIGH
=
1
0
HIGH
=
4
0
HIGH
=
3
0
NORMAL
=
50
NORMAL
=
50
LOW
=
6
0
LOW
=
7
0
VERY_LOW
=
8
0
VERY_LOW
=
9
0
LOWEST
=
100
LOWEST
=
100
...
...
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