Skip to content

Commit 97d4695

Browse files
authored
[pls merge] openpose example (#787)
* tl upadte of Openpose * code style improvement * test * yapf * comments * openpose example * openpose data augmentation API * train function update * update non mask case * add args.parser * add args.parser for log * add inference * paf process added * paf install instrcution * add inference * update md * hao modified * remove useless files * hao arranged files * trainable * del * release prepro for keypoints / vgg19 break * writing inferencing * coco 2017 * TODO distrubuted training * distributed code in same file * add int wout hout * agg * train mode * add cpm between vgg and stage1 * used own defined 10 layers of VGG19 * remove generated files (#801) * add mode; * remove openpose from current repo * Update CHANGELOG.md * add keypoint docs; * yapf - prepro * fix yapf * yapf
1 parent 748ea85 commit 97d4695

File tree

7 files changed

+630
-10
lines changed

7 files changed

+630
-10
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ To release a new version, please update the changelog as followed:
8181
- Add `tl.files.load_graph_` (PR #751)
8282
- Add `tl.files.save_graph_and_params` (PR #751)
8383
- Add `tl.files.load_graph_and_params` (PR #751)
84+
- Add `tl.prepro.keypoint_random_xxx` (PR #787)
8485
- Documentation:
8586
- Add binary, ternary and dorefa links (PR #711)
8687
- Update input scale of VGG16 and VGG19 to 0~1 (PR #736)
@@ -152,6 +153,7 @@ To release a new version, please update the changelog as followed:
152153
- @mutewall: #735
153154
- @thangvubk: #759
154155
- @JunbinWang: #796
156+
- @boldjoel: #787
155157

156158
## [1.9.1] - 2018-07-30
157159

docs/modules/prepro.rst

+29
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ Some of the code in this package are borrowed from Keras.
8787
obj_box_shift
8888
obj_box_zoom
8989

90+
keypoint_random_crop
91+
keypoint_random_crop2
92+
keypoint_random_rotate
93+
keypoint_random_flip
94+
keypoint_random_resize
95+
keypoint_random_resize_shortestedge
96+
9097
pad_sequences
9198
remove_pad_sequences
9299
process_sequences
@@ -416,8 +423,30 @@ Image Aug - Zoom
416423
^^^^^^^^^^^^^^^^^^^^^^^^^
417424
.. autofunction:: obj_box_zoom
418425

426+
Keypoints
427+
------------
419428

429+
Image Aug - Crop
430+
^^^^^^^^^^^^^^^^^^^^
431+
.. autofunction:: keypoint_random_crop
432+
433+
.. autofunction:: keypoint_random_crop2
434+
435+
Image Aug - Rotate
436+
^^^^^^^^^^^^^^^^^^^^
437+
.. autofunction:: keypoint_random_rotate
438+
439+
Image Aug - Flip
440+
^^^^^^^^^^^^^^^^^^^^
441+
.. autofunction:: keypoint_random_flip
442+
443+
Image Aug - Resize
444+
^^^^^^^^^^^^^^^^^^^^
445+
.. autofunction:: keypoint_random_resize
420446

447+
Image Aug - Resize Shortest Edge
448+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
449+
.. autofunction:: keypoint_random_resize_shortestedge
421450

422451

423452
Sequence

example/tutorial_models_vgg19.py

+28-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"""VGG-19 for ImageNet using TL models."""
44

55
import time
6+
import skimage
7+
import skimage.io
8+
import skimage.transform
69
import numpy as np
710
import tensorflow as tf
811
import tensorlayer as tl
@@ -24,17 +27,37 @@
2427

2528
vgg.print_layers()
2629

27-
img1 = tl.vis.read_image('data/tiger.jpeg')
28-
img1 = tl.prepro.imresize(img1, (224, 224))
30+
31+
# img1 = tl.vis.read_image('data/tiger.jpeg')
32+
# img1 = tl.prepro.imresize(img1, (224, 224))
33+
def load_image(path):
34+
# load image
35+
img = skimage.io.imread(path)
36+
img = img / 255.0
37+
if ((0 <= img).all() and (img <= 1.0).all()) is False:
38+
raise Exception("image value should be [0, 1]")
39+
# print "Original Image Shape: ", img.shape
40+
# we crop image from center
41+
short_edge = min(img.shape[:2])
42+
yy = int((img.shape[0] - short_edge) / 2)
43+
xx = int((img.shape[1] - short_edge) / 2)
44+
crop_img = img[yy:yy + short_edge, xx:xx + short_edge]
45+
# resize to 224, 224
46+
resized_img = skimage.transform.resize(crop_img, (224, 224), anti_aliasing=False)
47+
return resized_img
48+
49+
50+
img1 = load_image("data/tiger.jpeg") # test data in github
51+
img1 = img1.reshape((1, 224, 224, 3))
2952

3053
# rescale pixels values in the range of 0-1
31-
img1 = img1 / 255.0
54+
# img1 = img1 / 255.0
3255
if ((0 <= img1).all() and (img1 <= 1.0).all()) is False:
3356
raise Exception("image value should be [0, 1]")
3457

35-
_ = sess.run(probs, feed_dict={x: [img1]})[0] # 1st time takes time to compile
58+
_ = sess.run(probs, feed_dict={x: img1})[0] # 1st time takes time to compile
3659
start_time = time.time()
37-
prob = sess.run(probs, feed_dict={x: [img1]})[0]
60+
prob = sess.run(probs, feed_dict={x: img1})[0]
3861
print(" End time : %.5ss" % (time.time() - start_time))
3962
preds = (np.argsort(prob)[::-1])[0:5]
4063
for p in preds:

example/tutorial_vgg19.py

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ def Vgg19_simple_api(rgb):
233233

234234
img1 = load_image("data/tiger.jpeg") # test data in github
235235
img1 = img1.reshape((1, 224, 224, 3))
236+
236237
start_time = time.time()
237238
prob = sess.run(probs, feed_dict={x: img1})
238239
print("End time : %.5ss" % (time.time() - start_time))

tensorlayer/files/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -2277,6 +2277,7 @@ def _dlProgress(count, blockSize, totalSize, pbar=progress_bar):
22772277
filepath = os.path.join(working_directory, filename)
22782278

22792279
if not os.path.exists(filepath):
2280+
22802281
_download(filename, working_directory, url_source)
22812282
statinfo = os.stat(filepath)
22822283
logging.info('Succesfully downloaded %s %s bytes.' % (filename, statinfo.st_size)) # , 'bytes.')

tensorlayer/models/vgg19.py

+27-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,31 @@ def vgg19_simple_api(net_in, end_with):
5454
# with pixels values in the range of 0-255 and subtracts the mean image
5555
# values (calculated over the entire ImageNet training set).
5656

57-
# Rescale the input tensor with pixels values in the range of 0-255
58-
net_in.outputs = net_in.outputs * 255.0
59-
60-
mean = tf.constant([103.939, 116.779, 123.68], dtype=tf.float32, shape=[1, 1, 1, 3], name='img_mean')
61-
net_in.outputs = net_in.outputs - mean
57+
# # Rescale the input tensor with pixels values in the range of 0-255
58+
# net_in.outputs = net_in.outputs * 255.0
59+
# red, green, blue = tf.split(net_in.outputs, 3, 3)
60+
VGG_MEAN = [103.939, 116.779, 123.68]
61+
#
62+
# bgr = tf.concat([
63+
# blue - VGG_MEAN[0],
64+
# green - VGG_MEAN[1],
65+
# red - VGG_MEAN[2],
66+
# ], axis=3)
67+
# # mean = tf.constant([103.939, 116.779, 123.68], dtype=tf.float32, shape=[1, 1, 1, 3], name='img_mean')
68+
# # net_in.outputs = net_in.outputs - mean
69+
# net_in.outputs = bgr
70+
rgb = net_in.outputs
71+
rgb_scaled = rgb * 255.0
72+
# Convert RGB to BGR
73+
red, green, blue = tf.split(rgb_scaled, 3, 3)
74+
75+
bgr = tf.concat([
76+
blue - VGG_MEAN[0],
77+
green - VGG_MEAN[1],
78+
red - VGG_MEAN[2],
79+
], axis=3)
80+
81+
net_in.outputs = bgr
6282

6383
layers = [
6484
# conv1
@@ -163,6 +183,8 @@ def restore_params(self, sess):
163183
b = np.asarray(val[1][1])
164184
print(" Loading %s: %s, %s" % (val[0], W.shape, b.shape))
165185
params.extend([W, b])
186+
if len(self.all_params) == len(params):
187+
break
166188

167189
print("Restoring model from npz file")
168190
assign_params(sess, params, self.net)

0 commit comments

Comments
 (0)