def _create_joint_tensor(self, tensor, name = 'joint_tensor',debug = False):
""" TensorFlow Computation of Joint Position
Args:
tensor : Prediction Tensor Shape [nbStack x 64 x 64 x outDim] or [64 x 64 x outDim]
name : name of the tensor
Returns:
out : Tensor of joints position
Comment:
Genuinely Agreeing this tensor is UGLY. If you don't trust me, look at
'prediction' node in TensorBoard.
In my defence, I implement it to compare computation times with numpy.
"""
with tf.name_scope(name):
shape = tensor.get_shape().as_list()
if debug:
print(shape)
if len(shape) == 3:
resh = tf.reshape(tensor[:,:,0], [-1])
elif len(shape) == 4:
resh = tf.reshape(tensor[-1,:,:,0], [-1])
if debug:
print(resh)
arg = tf.arg_max(resh,0)
if debug:
print(arg, arg.get_shape(), arg.get_shape().as_list())
joints = tf.expand_dims(tf.stack([arg // tf.to_int64(shape[1]), arg % tf.to_int64(shape[1])], axis = -1), axis = 0)
for i in range(1, shape[-1]):
if len(shape) == 3:
resh = tf.reshape(tensor[:,:,i], [-1])
elif len(shape) == 4:
resh = tf.reshape(tensor[-1,:,:,i], [-1])
arg = tf.arg_max(resh,0)
j = tf.expand_dims(tf.stack([arg // tf.to_int64(shape[1]), arg % tf.to_int64(shape[1])], axis = -1), axis = 0)
joints = tf.concat([joints, j], axis = 0)
return tf.identity(joints, name = 'joints')
评论列表
文章目录