Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
15133229
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
15133229
编写于
11月 08, 2017
作者:
L
Luo Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add doc for image.py
上级
ee82e660
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
170 addition
and
133 deletion
+170
-133
doc/api/v2/data.rst
doc/api/v2/data.rst
+5
-108
doc/api/v2/data/data_reader.rst
doc/api/v2/data/data_reader.rst
+36
-0
doc/api/v2/data/dataset.rst
doc/api/v2/data/dataset.rst
+75
-0
doc/api/v2/data/image.rst
doc/api/v2/data/image.rst
+5
-0
python/paddle/v2/image.py
python/paddle/v2/image.py
+49
-25
未找到文件。
doc/api/v2/data.rst
浏览文件 @
15133229
...
...
@@ -2,112 +2,9 @@
Data Reader Interface and DataSets
==================================
.. toctree::
:maxdepth: 1
DataTypes
=========
.. automodule:: paddle.v2.data_type
:members:
:noindex:
DataFeeder
==========
.. automodule:: paddle.v2.data_feeder
:members:
:noindex:
Reader
======
.. automodule:: paddle.v2.reader
:members:
:noindex:
.. automodule:: paddle.v2.reader.creator
:members:
:noindex:
minibatch
=========
.. automodule:: paddle.v2.minibatch
:members:
:noindex:
Dataset
=======
.. automodule:: paddle.v2.dataset
:members:
:noindex:
mnist
+++++
.. automodule:: paddle.v2.dataset.mnist
:members:
:noindex:
cifar
+++++
.. automodule:: paddle.v2.dataset.cifar
:members:
:noindex:
conll05
+++++++
.. automodule:: paddle.v2.dataset.conll05
:members: get_dict,get_embedding,test
:noindex:
imdb
++++
.. automodule:: paddle.v2.dataset.imdb
:members:
:noindex:
imikolov
++++++++
.. automodule:: paddle.v2.dataset.imikolov
:members:
:noindex:
movielens
+++++++++
.. automodule:: paddle.v2.dataset.movielens
:members:
:noindex:
.. autoclass:: paddle.v2.dataset.movielens.MovieInfo
:noindex:
.. autoclass:: paddle.v2.dataset.movielens.UserInfo
:noindex:
sentiment
+++++++++
.. automodule:: paddle.v2.dataset.sentiment
:members:
:noindex:
uci_housing
+++++++++++
.. automodule:: paddle.v2.dataset.uci_housing
:members:
:noindex:
wmt14
+++++
.. automodule:: paddle.v2.dataset.wmt14
:members:
:noindex:
data/data_reader.rst
data/image.rst
data/dataset.rst
doc/api/v2/data/data_reader.rst
0 → 100644
浏览文件 @
15133229
=====================
Data Reader Interface
=====================
DataTypes
=========
.. automodule:: paddle.v2.data_type
:members:
:noindex:
DataFeeder
==========
.. automodule:: paddle.v2.data_feeder
:members:
:noindex:
Reader
======
.. automodule:: paddle.v2.reader
:members:
:noindex:
.. automodule:: paddle.v2.reader.creator
:members:
:noindex:
minibatch
=========
.. automodule:: paddle.v2.minibatch
:members:
:noindex:
doc/api/v2/data/dataset.rst
0 → 100644
浏览文件 @
15133229
Dataset
=======
.. automodule:: paddle.v2.dataset
:members:
:noindex:
mnist
+++++
.. automodule:: paddle.v2.dataset.mnist
:members:
:noindex:
cifar
+++++
.. automodule:: paddle.v2.dataset.cifar
:members:
:noindex:
conll05
+++++++
.. automodule:: paddle.v2.dataset.conll05
:members: get_dict,get_embedding,test
:noindex:
imdb
++++
.. automodule:: paddle.v2.dataset.imdb
:members:
:noindex:
imikolov
++++++++
.. automodule:: paddle.v2.dataset.imikolov
:members:
:noindex:
movielens
+++++++++
.. automodule:: paddle.v2.dataset.movielens
:members:
:noindex:
.. autoclass:: paddle.v2.dataset.movielens.MovieInfo
:noindex:
.. autoclass:: paddle.v2.dataset.movielens.UserInfo
:noindex:
sentiment
+++++++++
.. automodule:: paddle.v2.dataset.sentiment
:members:
:noindex:
uci_housing
+++++++++++
.. automodule:: paddle.v2.dataset.uci_housing
:members:
:noindex:
wmt14
+++++
.. automodule:: paddle.v2.dataset.wmt14
:members:
:noindex:
doc/api/v2/data/image.rst
0 → 100644
浏览文件 @
15133229
Image Interface
===============
.. automodule:: paddle.v2.image
:members:
python/paddle/v2/image.py
浏览文件 @
15133229
import
numpy
as
np
try
:
import
cv2
except
ImportError
:
cv2
=
None
import
os
import
tarfile
import
cPickle
__all__
=
[
"load_image_bytes"
,
"load_image"
,
"resize_short"
,
"to_chw"
,
"center_crop"
,
"random_crop"
,
"left_right_flip"
,
"simple_transform"
,
"load_and_transform"
,
"batch_images_from_tar"
]
"""
This file contains some common interfaces for image preprocess.
Many users are confused about the image layout. We introduce
the image layout as follows.
- CHW Layout
- The abbreviations: C=channel, H=Height, W=Width
- The default layout of image opened by cv2 or PIL is HWC.
PaddlePaddle only supports the CHW layout. And CHW is simply
a transpose of HWC. It must transpose the input image.
- Color format: RGB or BGR
OpenCV use BGR color format. PIL use RGB color format. Both
formats can be used for training. Noted that, the format should
be keep consistent between the training and inference peroid.
"""
import
numpy
as
np
try
:
import
cv2
except
ImportError
:
cv2
=
None
import
os
import
tarfile
import
cPickle
__all__
=
[
"load_image_bytes"
,
"load_image"
,
"resize_short"
,
"to_chw"
,
"center_crop"
,
"random_crop"
,
"left_right_flip"
,
"simple_transform"
,
"load_and_transform"
,
"batch_images_from_tar"
]
def
batch_images_from_tar
(
data_file
,
...
...
@@ -36,17 +38,18 @@ def batch_images_from_tar(data_file,
num_per_batch
=
1024
):
"""
Read images from tar file and batch them into batch file.
param data_file: path of image tar file
type data_file: string
param dataset_name: 'train','test' or 'valid'
type dataset_name: string
param img2label: a dic with image file name as key
:param data_file: path of image tar file
:type data_file: string
:param dataset_name: 'train','test' or 'valid'
:type dataset_name: string
:param img2label: a dic with image file name as key
and image's label as value
type img2label: dic
param num_per_batch: image number per batch file
type num_per_batch: int
return: path of list file containing paths of batch file
rtype: string
:
type img2label: dic
:
param num_per_batch: image number per batch file
:
type num_per_batch: int
:
return: path of list file containing paths of batch file
:
rtype: string
"""
batch_dir
=
data_file
+
"_batch"
out_path
=
"%s/%s"
%
(
batch_dir
,
dataset_name
)
...
...
@@ -99,14 +102,16 @@ def load_image_bytes(bytes, is_color=True):
Example usage:
.. code-block:: python
with open('cat.jpg') as f:
im = load_image_bytes(f.read())
:param bytes: the input image bytes array.
:type
file
: str
:type
bytes
: str
:param is_color: If set is_color True, it will load and
return a color image. Otherwise, it will
load and return a gray image.
:type is_color: bool
"""
flag
=
1
if
is_color
else
0
file_bytes
=
np
.
asarray
(
bytearray
(
bytes
),
dtype
=
np
.
uint8
)
...
...
@@ -121,6 +126,7 @@ def load_image(file, is_color=True):
Example usage:
.. code-block:: python
im = load_image('cat.jpg')
:param file: the input image path.
...
...
@@ -128,6 +134,7 @@ def load_image(file, is_color=True):
:param is_color: If set is_color True, it will load and
return a color image. Otherwise, it will
load and return a gray image.
:type is_color: bool
"""
# cv2.IMAGE_COLOR for OpenCV3
# cv2.CV_LOAD_IMAGE_COLOR for older OpenCV Version
...
...
@@ -147,6 +154,7 @@ def resize_short(im, size):
Example usage:
.. code-block:: python
im = load_image('cat.jpg')
im = resize_short(im, 256)
...
...
@@ -175,6 +183,7 @@ def to_chw(im, order=(2, 0, 1)):
Example usage:
.. code-block:: python
im = load_image('cat.jpg')
im = resize_short(im, 256)
im = to_chw(im)
...
...
@@ -196,6 +205,7 @@ def center_crop(im, size, is_color=True):
Example usage:
.. code-block:: python
im = center_crop(im, 224)
:param im: the input image with HWC layout.
...
...
@@ -223,6 +233,7 @@ def random_crop(im, size, is_color=True):
Example usage:
.. code-block:: python
im = random_crop(im, 224)
:param im: the input image with HWC layout.
...
...
@@ -251,6 +262,7 @@ def left_right_flip(im):
Example usage:
.. code-block:: python
im = left_right_flip(im)
:paam im: input image with HWC layout
...
...
@@ -275,6 +287,7 @@ def simple_transform(im,
Example usage:
.. code-block:: python
im = simple_transform(im, 256, 224, True)
:param im: The input image with HWC layout.
...
...
@@ -285,6 +298,11 @@ def simple_transform(im,
:type crop_size: int
:param is_train: Whether it is training or not.
:type is_train: bool
:param is_color: whether the image is color or not.
:type is_color: bool
:param mean: the mean values, which can be element-wise mean values or
mean values per channel.
:type mean: numpy array | list
"""
im
=
resize_short
(
im
,
resize_size
)
if
is_train
:
...
...
@@ -324,6 +342,7 @@ def load_and_transform(filename,
Example usage:
.. code-block:: python
im = load_and_transform('cat.jpg', 256, 224, True)
:param filename: The file name of input image.
...
...
@@ -334,6 +353,11 @@ def load_and_transform(filename,
:type crop_size: int
:param is_train: Whether it is training or not.
:type is_train: bool
:param is_color: whether the image is color or not.
:type is_color: bool
:param mean: the mean values, which can be element-wise mean values or
mean values per channel.
:type mean: numpy array | list
"""
im
=
load_image
(
filename
)
im
=
simple_transform
(
im
,
resize_size
,
crop_size
,
is_train
,
is_color
,
mean
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录