Skip to content

Instantly share code, notes, and snippets.

View ethanyanjiali's full-sized avatar

Ethan Yanjia Li ethanyanjiali

View GitHub Profile
@ethanyanjiali
ethanyanjiali / joint.json
Created March 14, 2020 20:22
One annotation for MPII in JSON
{
"joints_vis": [
1,
1,
1,
1,
1,
1,
1,
1,
@ethanyanjiali
ethanyanjiali / process_scale.py
Created March 14, 2020 20:31
Process MPII Scale
# avoid invisible keypoints whose value are <= 0
masked_keypoint_x = tf.boolean_mask(keypoint_x, keypoint_x > 0)
masked_keypoint_y = tf.boolean_mask(keypoint_y, keypoint_y > 0)
# find \left-most, top, bottom, and right-most keypoints
keypoint_xmin = tf.reduce_min(masked_keypoint_x)
keypoint_xmax = tf.reduce_max(masked_keypoint_x)
keypoint_ymin = tf.reduce_min(masked_keypoint_y)
keypoint_ymax = tf.reduce_max(masked_keypoint_y)
@ethanyanjiali
ethanyanjiali / gaussian.py
Created March 14, 2020 21:06
Generate Gaussian Patch
scale = 1
size = 6 * sigma + 1
x, y = tf.meshgrid(tf.range(0, 6*sigma+1, 1), tf.range(0, 6*sigma+1, 1), indexing='xy')
# the center of the gaussian patch should be 1
center_x = size // 2
center_y = size // 2
# generate this 7x7 gaussian patch
gaussian_patch = tf.cast(tf.math.exp(-(tf.square(x - center_x) + tf.math.square(y - center_y)) / (tf.math.square(sigma) * 2)) * scale, dtype=tf.float32)
@ethanyanjiali
ethanyanjiali / loss.py
Last active March 14, 2020 21:15
HG Loss
# vanilla version
loss += tf.math.reduce_mean(tf.math.square(labels - output))
# improved version
weights = tf.cast(labels > 0, dtype=tf.float32) * 81 + 1
loss += tf.math.reduce_mean(tf.math.square(labels - output) * weights)