Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
4a19ac5a
Commit
4a19ac5a
authored
Jan 27, 2020
by
Liubov Batanina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move instruction
parent
5790810c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
39 deletions
+45
-39
dnn.hpp
modules/dnn/include/opencv2/dnn/dnn.hpp
+2
-2
human_parsing.py
samples/dnn/human_parsing.py
+43
-37
No files found.
modules/dnn/include/opencv2/dnn/dnn.hpp
View file @
4a19ac5a
...
...
@@ -47,9 +47,9 @@
#include "opencv2/core/async.hpp"
#if !defined CV_DOXYGEN && !defined CV_STATIC_ANALYSIS && !defined CV_DNN_DONT_ADD_EXPERIMENTAL_NS
#define CV__DNN_EXPERIMENTAL_NS_BEGIN namespace experimental_dnn_34_v1
5
{
#define CV__DNN_EXPERIMENTAL_NS_BEGIN namespace experimental_dnn_34_v1
6
{
#define CV__DNN_EXPERIMENTAL_NS_END }
namespace
cv
{
namespace
dnn
{
namespace
experimental_dnn_34_v1
5
{
}
using
namespace
experimental_dnn_34_v15
;
}}
namespace
cv
{
namespace
dnn
{
namespace
experimental_dnn_34_v1
6
{
}
using
namespace
experimental_dnn_34_v16
;
}}
#else
#define CV__DNN_EXPERIMENTAL_NS_BEGIN
#define CV__DNN_EXPERIMENTAL_NS_END
...
...
samples/dnn/human_parsing.py
View file @
4a19ac5a
#!/usr/bin/env python
'''
You can download the converted pb model from https://www.dropbox.com/s/qag9vzambhhkvxr/lip_jppnet_384.pb?dl=0
or convert the model yourself.
Follow these steps if you want to convert the original model yourself:
To get original .meta pre-trained model download https://drive.google.com/file/d/1BFVXgeln-bek8TCbRjN6utPAgRE0LJZg/view
For correct convert .meta to .pb model download original repository https://github.com/Engineering-Course/LIP_JPPNet
Change script evaluate_parsing_JPPNet-s2.py for human parsing
1. Remove preprocessing to create image_batch_origin:
with tf.name_scope("create_inputs"):
...
Add
image_batch_origin = tf.placeholder(tf.float32, shape=(2, None, None, 3), name='input')
2. Create input
image = cv2.imread(path/to/image)
image_rev = np.flip(image, axis=1)
input = np.stack([image, image_rev], axis=0)
3. Hardcode image_h and image_w shapes to determine output shapes.
We use default INPUT_SIZE = (384, 384) from evaluate_parsing_JPPNet-s2.py.
parsing_out1 = tf.reduce_mean(tf.stack([tf.image.resize_images(parsing_out1_100, INPUT_SIZE),
tf.image.resize_images(parsing_out1_075, INPUT_SIZE),
tf.image.resize_images(parsing_out1_125, INPUT_SIZE)]), axis=0)
Do similarly with parsing_out2, parsing_out3
4. Remove postprocessing. Last net operation:
raw_output = tf.reduce_mean(tf.stack([parsing_out1, parsing_out2, parsing_out3]), axis=0)
Change:
parsing_ = sess.run(raw_output, feed_dict={'input:0': input})
5. To save model after sess.run(...) add:
input_graph_def = tf.get_default_graph().as_graph_def()
output_node = "Mean_3"
output_graph_def = tf.graph_util.convert_variables_to_constants(sess, input_graph_def, output_node)
output_graph = "LIP_JPPNet.pb"
with tf.gfile.GFile(output_graph, "wb") as f:
f.write(output_graph_def.SerializeToString())'
'''
import
argparse
import
cv2
as
cv
import
numpy
as
np
import
cv2
as
cv
backends
=
(
cv
.
dnn
.
DNN_BACKEND_DEFAULT
,
cv
.
dnn
.
DNN_BACKEND_INFERENCE_ENGINE
,
cv
.
dnn
.
DNN_BACKEND_OPENCV
)
...
...
@@ -116,7 +157,7 @@ if __name__ == '__main__':
parser
=
argparse
.
ArgumentParser
(
description
=
'Use this script to run human parsing using JPPNet'
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
parser
.
add_argument
(
'--input'
,
'-i'
,
required
=
True
,
help
=
'Path to input image.'
)
parser
.
add_argument
(
'--model'
,
'-m'
,
required
=
True
,
help
=
'Path to pb model
(https://www.dropbox.com/s/qag9vzambhhkvxr/lip_jppnet_384.pb?dl=0)
.'
)
parser
.
add_argument
(
'--model'
,
'-m'
,
required
=
True
,
help
=
'Path to pb model.'
)
parser
.
add_argument
(
'--backend'
,
choices
=
backends
,
default
=
cv
.
dnn
.
DNN_BACKEND_DEFAULT
,
type
=
int
,
help
=
"Choose one of computation backends: "
"
%
d: automatically (by default), "
...
...
@@ -135,38 +176,3 @@ if __name__ == '__main__':
cv
.
namedWindow
(
winName
,
cv
.
WINDOW_AUTOSIZE
)
cv
.
imshow
(
winName
,
output
)
cv
.
waitKey
()
# To get original .meta pre-trained model download https://drive.google.com/file/d/1BFVXgeln-bek8TCbRjN6utPAgRE0LJZg/view
# For correct convert .meta to .pb model download original repository https://github.com/Engineering-Course/LIP_JPPNet
# Change script evaluate_parsing_JPPNet-s2.py for human parsing
# 1. Remove preprocessing to create image_batch_origin:
# - with tf.name_scope("create_inputs"):
# ...
# Add
# - image_batch_origin = tf.placeholder(tf.float32, shape=(2, None, None, 3), name='input')
#
# 2. Create input
# image = cv2.imread(path/to/image)
# image_rev = np.flip(image, axis=1)
# input = np.stack([image, image_rev], axis=0)
#
# 3. Hardcode image_h and image_w shapes to determine output shapes.
# We use default INPUT_SIZE = (384, 384) from evaluate_parsing_JPPNet-s2.py.
# - parsing_out1 = tf.reduce_mean(tf.stack([tf.image.resize_images(parsing_out1_100, INPUT_SIZE),
# tf.image.resize_images(parsing_out1_075, INPUT_SIZE),
# tf.image.resize_images(parsing_out1_125, INPUT_SIZE)]), axis=0)
# Do similarly with parsing_out2, parsing_out3
# 4. Remove postprocessing. Last net operation:
# raw_output = tf.reduce_mean(tf.stack([parsing_out1, parsing_out2, parsing_out3]), axis=0)
# Change:
# parsing_ = sess.run(raw_output, feed_dict={'input:0': input})
#
# 5. To save model after sess.run(...) add:
# input_graph_def = tf.get_default_graph().as_graph_def()
# output_node = "Mean_3"
# output_graph_def = tf.graph_util.convert_variables_to_constants(sess, input_graph_def, output_node)
#
# output_graph = "LIP_JPPNet.pb"
# with tf.gfile.GFile(output_graph, "wb") as f:
# f.write(output_graph_def.SerializeToString())
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