|
|
|
@ -1,45 +1,11 @@ |
|
|
|
|
import argparse |
|
|
|
|
import cv2 as cv |
|
|
|
|
import numpy as np |
|
|
|
|
import argparse |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backends = (cv.dnn.DNN_BACKEND_DEFAULT, cv.dnn.DNN_BACKEND_INFERENCE_ENGINE, cv.dnn.DNN_BACKEND_OPENCV) |
|
|
|
|
targets = (cv.dnn.DNN_TARGET_CPU, cv.dnn.DNN_TARGET_OPENCL, cv.dnn.DNN_TARGET_OPENCL_FP16, cv.dnn.DNN_TARGET_MYRIAD) |
|
|
|
|
|
|
|
|
|
# To get 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()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def preprocess(image_path): |
|
|
|
|
""" |
|
|
|
@ -149,8 +115,9 @@ def parse_human(image_path, model_path, backend=cv.dnn.DNN_BACKEND_OPENCV, targe |
|
|
|
|
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', help='Path to input image. Skip this argument to capture frames from a camera.') |
|
|
|
|
parser.add_argument('--model', '-m', required=True, help='Path to pb model.') |
|
|
|
|
parser.add_argument('--input', '-i', help='Path to input image.') |
|
|
|
|
parser.add_argument('--model', '-m', required=True, help='Path to pb model |
|
|
|
|
(https://drive.google.com/open?id=1XHvo111Gj1ZGoNUJt4Y4OsShrt_eUT34).') |
|
|
|
|
parser.add_argument('--backend', choices=backends, default=cv.dnn.DNN_BACKEND_DEFAULT, type=int, |
|
|
|
|
help="Choose one of computation backends: " |
|
|
|
|
"%d: automatically (by default), " |
|
|
|
@ -169,3 +136,38 @@ 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()) |
|
|
|
|