Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SeetaResearch
/
Dragon
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2356c658
authored
Aug 08, 2017
by
Ting PAN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove default inplace for densenet
1 parent
7e98dfd9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
72 additions
and
87 deletions
3rdparty/lib/README.md
Dragon/CMakeLists.txt
Dragon/include/operators/norm/batch_norm_op.h
Dragon/include/operators/norm/batch_renorm_op.h
Dragon/include/operators/norm/instance_norm_op.h
Dragon/modules/python/CMakeLists.txt
Dragon/python/dragon/vm/caffe/layers/common.py
README.md
examples/cifar10/gen_lmdb.py
3rdparty/lib/README.md
View file @
2356c65
...
@@ -3,4 +3,4 @@ This directory holds (*after you download them*):
...
@@ -3,4 +3,4 @@ This directory holds (*after you download them*):
-
libprotobuf.lib (For
``google protobuf``
, Windows Only)
-
libprotobuf.lib (For
``google protobuf``
, Windows Only)
-
cudnn.lib (For
``cudnn``
, Windows Only)
-
cudnn.lib (For
``cudnn``
, Windows Only)
-
libopenblas.lib (For
``cblas``
, Windows Only)
-
libopenblas.lib (For
``cblas``
, Windows Only)
-
python27.lib
(For
``python27
``
, Windows Only)
-
python27.lib
/python35.lib/python36.lib (For
``python27/35/36
``
, Windows Only)
Dragon/CMakeLists.txt
View file @
2356c65
...
@@ -23,7 +23,7 @@ set(3RDPARTY_DIR ${PROJECT_SOURCE_DIR}/../3rdparty)
...
@@ -23,7 +23,7 @@ set(3RDPARTY_DIR ${PROJECT_SOURCE_DIR}/../3rdparty)
# set your python environment
# set your python environment
set
(
PYTHON_DIR /usr/include/python2.7
)
# prefer
set
(
PYTHON_DIR /usr/include/python2.7
)
# prefer
#set(PYTHON_DIR /usr/include/python3.x) # optional, set specific version
#set(PYTHON_DIR /usr/include/python3.x) # optional, set specific version
#set(ANACONDA_DIR /xxx/anaconda) # optional,
set specific version below if using py3
#set(ANACONDA_DIR /xxx/anaconda) # optional,
root folder of anaconda, preset for 2.7, 3.5, and 3.6
set
(
NUMPY_DIR /xxx/numpy
)
# require, root folder of numpy package
set
(
NUMPY_DIR /xxx/numpy
)
# require, root folder of numpy package
# set CUDA compiling architecture
# set CUDA compiling architecture
...
@@ -83,7 +83,8 @@ include_directories(${NUMPY_DIR}/core/include)
...
@@ -83,7 +83,8 @@ include_directories(${NUMPY_DIR}/core/include)
include_directories
(
${
NUMPY_DIR
}
)
include_directories
(
${
NUMPY_DIR
}
)
include_directories
(
${
NUMPY_DIR
}
/numpy
)
include_directories
(
${
NUMPY_DIR
}
/numpy
)
include_directories
(
${
ANACONDA_DIR
}
/include/python2.7
)
include_directories
(
${
ANACONDA_DIR
}
/include/python2.7
)
include_directories
(
${
ANACONDA_DIR
}
/include/python3.x
)
include_directories
(
${
ANACONDA_DIR
}
/include/python3.5
)
include_directories
(
${
ANACONDA_DIR
}
/include/python3.6
)
include_directories
(
${
PYTHON_DIR
}
)
include_directories
(
${
PYTHON_DIR
}
)
include_directories
(
${
ANACONDA_DIR
}
/include
)
include_directories
(
${
ANACONDA_DIR
}
/include
)
...
...
Dragon/include/operators/norm/batch_norm_op.h
View file @
2356c65
...
@@ -19,7 +19,7 @@ class BatchNormOp : public Operator<Context> {
...
@@ -19,7 +19,7 @@ class BatchNormOp : public Operator<Context> {
momentum
(
OperatorBase
::
GetSingleArg
<
float
>
(
"momentum"
,
float
(
0
.
9
))),
momentum
(
OperatorBase
::
GetSingleArg
<
float
>
(
"momentum"
,
float
(
0
.
9
))),
eps
(
OperatorBase
::
GetSingleArg
<
float
>
(
"eps"
,
float
(
1e-3
))),
eps
(
OperatorBase
::
GetSingleArg
<
float
>
(
"eps"
,
float
(
1e-3
))),
use_stats
(
OperatorBase
::
GetSingleArg
<
int
>
(
"use_stats"
,
-
1
)),
use_stats
(
OperatorBase
::
GetSingleArg
<
int
>
(
"use_stats"
,
-
1
)),
inplace
(
OperatorBase
::
GetSingleArg
<
bool
>
(
"inplace"
,
tru
e
))
{}
inplace
(
OperatorBase
::
GetSingleArg
<
bool
>
(
"inplace"
,
fals
e
))
{}
void
RunOnDevice
()
override
;
void
RunOnDevice
()
override
;
template
<
typename
T
>
void
RunWithType
();
template
<
typename
T
>
void
RunWithType
();
...
...
Dragon/include/operators/norm/batch_renorm_op.h
View file @
2356c65
...
@@ -22,7 +22,7 @@ class BatchRenormOp : public Operator<Context> {
...
@@ -22,7 +22,7 @@ class BatchRenormOp : public Operator<Context> {
d_max
(
OperatorBase
::
GetSingleArg
<
float
>
(
"d_max"
,
float
(
5
.
0
))),
d_max
(
OperatorBase
::
GetSingleArg
<
float
>
(
"d_max"
,
float
(
5
.
0
))),
t_delta
(
OperatorBase
::
GetSingleArg
<
float
>
(
"t_delta"
,
float
(
1
.
0
))),
t_delta
(
OperatorBase
::
GetSingleArg
<
float
>
(
"t_delta"
,
float
(
1
.
0
))),
use_stats
(
OperatorBase
::
GetSingleArg
<
int
>
(
"use_stats"
,
-
1
)),
use_stats
(
OperatorBase
::
GetSingleArg
<
int
>
(
"use_stats"
,
-
1
)),
inplace
(
OperatorBase
::
GetSingleArg
<
bool
>
(
"inplace"
,
tru
e
)),
inplace
(
OperatorBase
::
GetSingleArg
<
bool
>
(
"inplace"
,
fals
e
)),
t_r_max
(
float
(
1
.
0
)),
t_d_max
(
float
(
0
.
0
)),
t_val
(
float
(
0
.
0
))
{}
t_r_max
(
float
(
1
.
0
)),
t_d_max
(
float
(
0
.
0
)),
t_val
(
float
(
0
.
0
))
{}
void
RunOnDevice
()
override
;
void
RunOnDevice
()
override
;
...
...
Dragon/include/operators/norm/instance_norm_op.h
View file @
2356c65
...
@@ -17,7 +17,7 @@ class InstanceNormOp : public Operator<Context> {
...
@@ -17,7 +17,7 @@ class InstanceNormOp : public Operator<Context> {
InstanceNormOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
InstanceNormOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
Context
>
(
op_def
,
ws
),
:
Operator
<
Context
>
(
op_def
,
ws
),
eps
(
OperatorBase
::
GetSingleArg
<
float
>
(
"eps"
,
float
(
1e-3
))),
eps
(
OperatorBase
::
GetSingleArg
<
float
>
(
"eps"
,
float
(
1e-3
))),
inplace
(
OperatorBase
::
GetSingleArg
<
bool
>
(
"inplace"
,
tru
e
))
{}
inplace
(
OperatorBase
::
GetSingleArg
<
bool
>
(
"inplace"
,
fals
e
))
{}
void
RunOnDevice
()
override
;
void
RunOnDevice
()
override
;
template
<
typename
T
>
void
RunWithType
();
template
<
typename
T
>
void
RunWithType
();
...
...
Dragon/modules/python/CMakeLists.txt
View file @
2356c65
...
@@ -20,6 +20,9 @@ endforeach()
...
@@ -20,6 +20,9 @@ endforeach()
if
(
UNIX AND WITH_CUDNN
)
if
(
UNIX AND WITH_CUDNN
)
TARGET_LINK_LIBRARIES
(
${
PROJECT_NAME
}
_python cudnn
)
TARGET_LINK_LIBRARIES
(
${
PROJECT_NAME
}
_python cudnn
)
endif
()
endif
()
if
(
UNIX AND WITH_BLAS
)
TARGET_LINK_LIBRARIES
(
${
PROJECT_NAME
}
_python openblas
)
endif
()
# ---[ link platforms
# ---[ link platforms
if
(
UNIX
)
if
(
UNIX
)
...
...
Dragon/python/dragon/vm/caffe/layers/common.py
View file @
2356c65
...
@@ -177,9 +177,9 @@ class BatchNormLayer(Layer):
...
@@ -177,9 +177,9 @@ class BatchNormLayer(Layer):
'momentum'
:
param
.
moving_average_fraction
,
'momentum'
:
param
.
moving_average_fraction
,
'eps'
:
param
.
eps
}
'eps'
:
param
.
eps
}
# mean, var, factor are set to 0 in order to do statistics
# mean, var, factor are set to 0 in order to do statistics
mean
=
Tensor
(
LayerParameter
.
name
+
'@param0'
)
.
Constant
()
mean
=
Tensor
(
LayerParameter
.
name
+
'@param0'
)
.
Constant
(
value
=
0.0
)
var
=
Tensor
(
LayerParameter
.
name
+
'@param1'
)
.
Constant
()
var
=
Tensor
(
LayerParameter
.
name
+
'@param1'
)
.
Constant
(
value
=
0.0
)
factor
=
Tensor
(
LayerParameter
.
name
+
'@param2'
)
.
Constant
()
factor
=
Tensor
(
LayerParameter
.
name
+
'@param2'
)
.
Constant
(
value
=
0.0
)
# in dragon, set diff as None will ignore computing grad automatically
# in dragon, set diff as None will ignore computing grad automatically
# but in bvlc-caffe1, you must set lr_mult = 0 manually
# but in bvlc-caffe1, you must set lr_mult = 0 manually
self
.
_blobs
.
append
({
'data'
:
mean
,
'diff'
:
None
})
self
.
_blobs
.
append
({
'data'
:
mean
,
'diff'
:
None
})
...
@@ -202,9 +202,9 @@ class BatchRenormLayer(Layer):
...
@@ -202,9 +202,9 @@ class BatchRenormLayer(Layer):
'r_max'
:
float
(
param
.
r_max
),
'r_max'
:
float
(
param
.
r_max
),
'd_max'
:
float
(
param
.
d_max
),
'd_max'
:
float
(
param
.
d_max
),
't_delta'
:
float
(
param
.
t_delta
)}
't_delta'
:
float
(
param
.
t_delta
)}
mean
=
Tensor
(
LayerParameter
.
name
+
'@param0'
)
.
Constant
()
mean
=
Tensor
(
LayerParameter
.
name
+
'@param0'
)
.
Constant
(
value
=
0.0
)
var
=
Tensor
(
LayerParameter
.
name
+
'@param1'
)
.
Constant
()
var
=
Tensor
(
LayerParameter
.
name
+
'@param1'
)
.
Constant
(
value
=
0.0
)
factor
=
Tensor
(
LayerParameter
.
name
+
'@param2'
)
.
Constant
()
factor
=
Tensor
(
LayerParameter
.
name
+
'@param2'
)
.
Constant
(
value
=
0.0
)
self
.
_blobs
.
append
({
'data'
:
mean
,
'diff'
:
None
})
self
.
_blobs
.
append
({
'data'
:
mean
,
'diff'
:
None
})
self
.
_blobs
.
append
({
'data'
:
var
,
'diff'
:
None
})
self
.
_blobs
.
append
({
'data'
:
var
,
'diff'
:
None
})
self
.
_blobs
.
append
({
'data'
:
factor
,
'diff'
:
None
})
self
.
_blobs
.
append
({
'data'
:
factor
,
'diff'
:
None
})
...
@@ -253,19 +253,27 @@ class BNLayer(Layer):
...
@@ -253,19 +253,27 @@ class BNLayer(Layer):
def
__init__
(
self
,
LayerParameter
):
def
__init__
(
self
,
LayerParameter
):
super
(
BNLayer
,
self
)
.
__init__
(
LayerParameter
)
super
(
BNLayer
,
self
)
.
__init__
(
LayerParameter
)
param
=
LayerParameter
.
batch_norm_param
bn_param
=
LayerParameter
.
batch_norm_param
self
.
_param
=
{
'use_stats'
:
int
(
param
.
use_global_stats
)
scale_param
=
LayerParameter
.
scale_param
if
param
.
HasField
(
'use_global_stats'
)
else
-
1
,
self
.
_param
=
{
'use_stats'
:
int
(
bn_param
.
use_global_stats
)
'momentum'
:
param
.
moving_average_fraction
,
if
bn_param
.
HasField
(
'use_global_stats'
)
else
-
1
,
'eps'
:
param
.
eps
}
'momentum'
:
bn_param
.
moving_average_fraction
,
mean
=
Tensor
(
LayerParameter
.
name
+
'@param0'
)
.
Constant
()
'eps'
:
bn_param
.
eps
}
var
=
Tensor
(
LayerParameter
.
name
+
'@param1'
)
.
Constant
()
mean
=
Tensor
(
LayerParameter
.
name
+
'@param0'
)
.
Constant
(
value
=
0.0
)
scale
=
Tensor
(
LayerParameter
.
name
+
'@param2'
)
.
Constant
(
value
=
1.0
)
var
=
Tensor
(
LayerParameter
.
name
+
'@param1'
)
.
Constant
(
value
=
0.0
)
bias
=
Tensor
(
LayerParameter
.
name
+
'@param3'
)
.
Constant
(
value
=
0.0
)
scale
=
Tensor
(
LayerParameter
.
name
+
'@param2'
)
scale_diff
=
Tensor
(
LayerParameter
.
name
+
'@param2_grad'
)
bias
=
Tensor
(
LayerParameter
.
name
+
'@param3'
)
bias_diff
=
Tensor
(
LayerParameter
.
name
+
'@param3_grad'
)
if
scale_param
.
HasField
(
'filler'
):
self
.
Fill
(
scale
,
scale_param
,
'filler'
)
else
:
scale
.
Constant
(
value
=
1.0
)
self
.
Fill
(
bias
,
scale_param
,
'bias_filler'
)
self
.
norm_blobs
=
[{
'data'
:
mean
,
'diff'
:
None
},
self
.
norm_blobs
=
[{
'data'
:
mean
,
'diff'
:
None
},
{
'data'
:
var
,
'diff'
:
None
}]
{
'data'
:
var
,
'diff'
:
None
}]
self
.
scale_blobs
=
[{
'data'
:
scale
,
'diff'
:
Tensor
(
scale
.
name
+
'_grad'
)
},
self
.
scale_blobs
=
[{
'data'
:
scale
,
'diff'
:
scale_diff
},
{
'data'
:
bias
,
'diff'
:
Tensor
(
bias
.
name
+
'_grad'
)
}]
{
'data'
:
bias
,
'diff'
:
bias_diff
}]
self
.
_blobs
.
extend
(
self
.
norm_blobs
)
self
.
_blobs
.
extend
(
self
.
norm_blobs
)
self
.
_blobs
.
extend
(
self
.
scale_blobs
)
self
.
_blobs
.
extend
(
self
.
scale_blobs
)
...
...
README.md
View file @
2356c65
...
@@ -18,10 +18,16 @@
...
@@ -18,10 +18,16 @@
3.
(Optional) Download 3rdparty.zip and unzip to Dragon/3rdparty (Out of source code dir)
3.
(Optional) Download 3rdparty.zip and unzip to Dragon/3rdparty (Out of source code dir)
[*Win64*](https://pan.baidu.com/s/1pLmGOLt) (OpenBLAS / Protobuf2.6 for VS2013 / CUDNN v6 / Microsoft MPI)
[*Win64-VS2013*](https://pan.baidu.com/s/1miGAZl2) (OpenBLAS / Protobuf2.6 for VS2013 / CUDNN v7 / Microsoft MPI)
[*Win64-VS2015*](https://pan.baidu.com/s/1c2eX6lq) (OpenBLAS / Protobuf2.6 for VS2015 / CUDNN v7 / Microsoft MPI)
[*Linux64*](https://pan.baidu.com/s/1qXPEOWG) (OpenMPI)
[*Linux64*](https://pan.baidu.com/s/1qXPEOWG) (OpenMPI)
For Windows, ``python27/35/36.lib`` should be copied to ``Dragon/3rdparty/lib``, it depends on the version of Python.
For Linux, ``libpython-dev``, ``libprotobuf-dev``, ``libopenblas-dev`` and ``cuDNN`` should be installed by yourself.
4.
Install Python Requirements
4.
Install Python Requirements
```Shell
```Shell
...
@@ -30,12 +36,12 @@
...
@@ -30,12 +36,12 @@
```
```
5.
Configure Dragon/CMakeLists.txt
5.
Configure Dragon/CMakeLists.txt
-
Select optional libraries
[
PYTHON3 / CUDA / CUDNN / BLAS / SSE / MPI
/ MPI_CUDA_AWARE / CUDA_FP16
]
-
Select optional libraries
[
PYTHON3 / CUDA / CUDNN / BLAS / SSE / MPI
]
-
Set 3rdparty path (recommend to keep defualt)
-
Set 3rdparty path (recommend to keep defualt)
-
Set Python include path & Numpy root path
-
Set Python include path & Numpy root path
-
Set CUDA compiling architectures if necessary
-
Set CUDA compiling architectures if necessary
-
GCC version(4.8+, 5.0-) should add
``-std=c++11``
to
``CUDA_NVCC_FLAGS``
, if
``nullptr``
is not found
-
GCC version(4.8+, 5.0-) should add
``-std=c++11``
to
``CUDA_NVCC_FLAGS``
, if
``nullptr``
is not found
-
We pre-generated files under
the
``Dragon/src/protos``
with protobuf-2.6, run protoc
by yourself if higher are required
-
We pre-generated files under
``Dragon/src/protos``
with protobuf-2.6, run
``protoc``
by yourself if higher are required
6.
Environment Variables
6.
Environment Variables
### Linux(Only for OpenMPI):
### Linux(Only for OpenMPI):
...
...
examples/cifar10/gen_lmdb.py
View file @
2356c65
...
@@ -32,12 +32,6 @@ def wrapper_str(raw_str):
...
@@ -32,12 +32,6 @@ def wrapper_str(raw_str):
def
extract_images
():
def
extract_images
():
prefix
=
'data/cifar-10-batches-py'
prefix
=
'data/cifar-10-batches-py'
extract_path
=
'data/extract'
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
extract_path
,
'JPEGImages'
)):
os
.
makedirs
(
os
.
path
.
join
(
extract_path
,
'JPEGImages'
))
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
extract_path
,
'ImageSets'
)):
os
.
makedirs
(
os
.
path
.
join
(
extract_path
,
'ImageSets'
))
batches
=
[
os
.
path
.
join
(
prefix
,
'data_batch_{}'
.
format
(
i
))
for
i
in
xrange
(
1
,
6
)]
batches
=
[
os
.
path
.
join
(
prefix
,
'data_batch_{}'
.
format
(
i
))
for
i
in
xrange
(
1
,
6
)]
batches
+=
[
os
.
path
.
join
(
prefix
,
'test_batch'
)]
batches
+=
[
os
.
path
.
join
(
prefix
,
'test_batch'
)]
...
@@ -60,28 +54,13 @@ def extract_images():
...
@@ -60,28 +54,13 @@ def extract_images():
label
=
dict
[
wrapper_str
(
'labels'
)][
item_idx
]
label
=
dict
[
wrapper_str
(
'labels'
)][
item_idx
]
im
=
im
.
transpose
((
1
,
2
,
0
))
im
=
im
.
transpose
((
1
,
2
,
0
))
im
=
im
[:,
:,
::
-
1
]
im
=
im
[:,
:,
::
-
1
]
filename
=
str
(
total_idx
)
.
zfill
(
ZFILL
)
+
'.jpg'
images_list
.
append
((
im
,
str
(
label
)))
cv2
.
imwrite
(
os
.
path
.
join
(
extract_path
,
'JPEGImages'
,
filename
),
im
)
images_list
.
append
((
filename
,
str
(
label
)))
total_idx
+=
1
total_idx
+=
1
# make list
return
images_list
with
open
(
os
.
path
.
join
(
extract_path
,
'ImageSets'
,
'train.txt'
),
'w'
)
as
f
:
for
i
in
xrange
(
50000
):
item
=
images_list
[
i
][
0
]
+
' '
+
images_list
[
i
][
1
]
if
i
!=
49999
:
item
+=
'
\n
'
f
.
write
(
item
)
with
open
(
os
.
path
.
join
(
extract_path
,
'ImageSets'
,
'test.txt'
),
'w'
)
as
f
:
for
i
in
xrange
(
50000
,
60000
):
item
=
images_list
[
i
][
0
]
+
' '
+
images_list
[
i
][
1
]
if
i
!=
59999
:
item
+=
'
\n
'
f
.
write
(
item
)
def
make_db
(
image_path
,
label_path
,
database_path
,
pad
=
0
):
def
make_db
(
images_list
,
database_path
,
pad
=
0
):
if
os
.
path
.
isfile
(
label_path
)
is
False
:
raise
ValueError
(
'input path is empty or wrong.'
)
if
os
.
path
.
isdir
(
database_path
)
is
True
:
if
os
.
path
.
isdir
(
database_path
)
is
True
:
raise
ValueError
(
'the database path is already exist.'
)
raise
ValueError
(
'the database path is already exist.'
)
...
@@ -90,42 +69,35 @@ def make_db(image_path, label_path, database_path, pad=0):
...
@@ -90,42 +69,35 @@ def make_db(image_path, label_path, database_path, pad=0):
db
=
LMDB
(
max_commit
=
10000
)
db
=
LMDB
(
max_commit
=
10000
)
db
.
open
(
database_path
,
mode
=
'w'
)
db
.
open
(
database_path
,
mode
=
'w'
)
total_line
=
sum
(
1
for
line
in
open
(
label_path
)
)
total_line
=
len
(
images_list
)
count
=
0
count
=
0
zfill_flag
=
'{0:0
%
d}'
%
(
ZFILL
)
zfill_flag
=
'{0:0
%
d}'
%
(
ZFILL
)
encode_param
=
[
int
(
cv2
.
IMWRITE_JPEG_QUALITY
),
95
]
start_time
=
time
.
time
()
start_time
=
time
.
time
()
with
open
(
label_path
,
'r'
)
as
input_file
:
for
record
in
images_list
:
for
record
in
input_file
:
count
+=
1
count
+=
1
if
count
%
10000
==
0
:
if
count
%
10000
==
0
:
now_time
=
time
.
time
()
now_time
=
time
.
time
()
print
(
'{0} / {1} in {2:.2f} sec'
.
format
(
print
(
'{0} / {1} in {2:.2f} sec'
.
format
(
count
,
total_line
,
now_time
-
start_time
))
count
,
total_line
,
now_time
-
start_time
))
db
.
commit
()
db
.
commit
()
img
=
record
[
0
]
record
=
record
.
split
()
label
=
record
[
1
]
path
=
record
[
0
]
if
pad
>
0
:
label
=
record
[
1
]
pad_img
=
np
.
zeros
((
img
.
shape
[
0
]
+
2
*
pad
,
img
.
shape
[
1
]
+
2
*
pad
,
3
),
dtype
=
np
.
uint8
)
img
=
cv2
.
imread
(
os
.
path
.
join
(
image_path
,
path
))
pad_img
[
pad
:
pad
+
img
.
shape
[
0
],
if
pad
>
0
:
pad_img
=
np
.
zeros
((
img
.
shape
[
0
]
+
2
*
pad
,
img
.
shape
[
1
]
+
2
*
pad
,
3
),
dtype
=
np
.
uint8
)
pad_img
[
pad
:
pad
+
img
.
shape
[
0
],
pad
:
pad
+
img
.
shape
[
1
],
:]
=
img
pad
:
pad
+
img
.
shape
[
1
],
:]
=
img
img
=
pad_img
img
=
pad_img
result
,
imgencode
=
cv2
.
imencode
(
'.jpg'
,
img
,
encode_param
)
datum
=
caffe_pb2
.
Datum
()
datum
=
caffe_pb2
.
Datum
()
datum
.
height
,
datum
.
width
,
datum
.
channels
=
img
.
shape
datum
.
height
,
datum
.
width
,
datum
.
channels
=
img
.
shape
datum
.
label
=
int
(
label
)
datum
.
label
=
int
(
label
)
datum
.
encoded
=
Tru
e
datum
.
encoded
=
Fals
e
datum
.
data
=
imgencode
.
tostring
()
datum
.
data
=
img
.
tostring
()
db
.
put
(
zfill_flag
.
format
(
count
-
1
),
datum
.
SerializeToString
())
db
.
put
(
zfill_flag
.
format
(
count
-
1
),
datum
.
SerializeToString
())
now_time
=
time
.
time
()
now_time
=
time
.
time
()
print
(
'{0} / {1} in {2:.2f} sec'
.
format
(
count
,
total_line
,
now_time
-
start_time
))
print
(
'{0} / {1} in {2:.2f} sec'
.
format
(
count
,
total_line
,
now_time
-
start_time
))
...
@@ -134,7 +106,6 @@ def make_db(image_path, label_path, database_path, pad=0):
...
@@ -134,7 +106,6 @@ def make_db(image_path, label_path, database_path, pad=0):
db
.
commit
()
db
.
commit
()
db
.
close
()
db
.
close
()
shutil
.
copy
(
label_path
,
database_path
+
'/image_list.txt'
)
end_time
=
time
.
time
()
end_time
=
time
.
time
()
print
(
'{0} images have been stored in the database.'
.
format
(
total_line
))
print
(
'{0} images have been stored in the database.'
.
format
(
total_line
))
print
(
'This task finishes within {0:.2f} seconds.'
.
format
(
print
(
'This task finishes within {0:.2f} seconds.'
.
format
(
...
@@ -147,12 +118,8 @@ if __name__ == '__main__':
...
@@ -147,12 +118,8 @@ if __name__ == '__main__':
untar
(
'data/cifar-10-python.tar.gz'
)
untar
(
'data/cifar-10-python.tar.gz'
)
extract_images
()
images_list
=
extract_images
()
make_db
(
'data/extract/JPEGImages'
,
make_db
(
images_list
[
0
:
50000
],
'data/train_lmdb'
)
'data/extract/ImageSets/train.txt'
,
'data/train_lmdb'
)
make_db
(
'data/extract/JPEGImages'
,
make_db
(
images_list
[
50000
:
60000
],
'data/test_lmdb'
)
'data/extract/ImageSets/test.txt'
,
'data/test_lmdb'
)
Write
Preview
Markdown
is supported
Attach a file
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 post a comment