Esempio n. 1
0
    # images to be shown
    image_list = list()
    image_list.append('./data/1.png')
    image_list.append('./data/2.png')
    image_list.append('./data/3.png')
    image_list.append('./data/4.png')
    image_list.append('./data/5.png')

    # network input
    image_tf = tf.placeholder(tf.float32, shape=(1, 240, 320, 3))
    hand_side_tf = tf.constant([[1.0, 0.0]
                                ])  # left hand (true for all samples provided)
    evaluation = tf.placeholder_with_default(True, shape=())

    # build network
    net = PoseEstimationNetwork()
    print("Line 48:Let's test!\n")
    hand_scoremap_tf, image_crop_tf, scale_crop_tf, center_tf = net.HandSegCrop(
        image_tf)
    print("Oops,testcrop_line 49==> The formu is :", hand_scoremap_tf.shape)
    # Start TF
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.8)
    sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))

    # initialize network
    # net.init(sess)
    # retrained version: HandSegNet
    last_cpt = tf.train.latest_checkpoint(PATH_TO_HANDSEGNET_SNAPSHOTS)
    assert last_cpt is not None, "Could not locate snapshot to load. Did you already train the network and set the path accordingly?"
    load_weights_from_snapshot(sess,
                               last_cpt,
              'max_iter': 30000,
              'show_loss_freq': 1000,
              'snapshot_freq': 5000,
              'snapshot_dir': 'snapshots_posenet'}

# get dataset
dataset = BinaryDbReader(mode='training',
                         batch_size=8, shuffle=True, use_wrist_coord=False,
                         hand_crop=True, coord_uv_noise=True, crop_center_noise=True)

# build network graph
data = dataset.get()

# build network
evaluation = tf.placeholder_with_default(True, shape=())
net = PoseEstimationNetwork()
keypoints_scoremap = net.PoseNet(data['image_crop'], train=True)
s = data['scoremap'].get_shape().as_list()
keypoints_scoremap = [tf.image.resize_images(x, (s[1], s[2])) for x in keypoints_scoremap]

# Start TF
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.8)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
tf.train.start_queue_runners(sess=sess)

# Loss
loss = 0.0
s = data['scoremap'].get_shape().as_list()
vis = tf.cast(tf.reshape(data['keypoint_vis21'], [s[0], s[3]]), tf.float32)
for i, pred_item in enumerate(keypoints_scoremap):
    loss += tf.reduce_sum(vis * tf.sqrt(tf.reduce_mean(tf.square(pred_item - data['scoremap']), [1, 2]))) / (tf.reduce_sum(vis) + 0.001)
    'snapshot_dir': 'snapshots_handsegnet'
}

# get dataset
dataset = BinaryDbReader(mode='training',
                         batch_size=8,
                         shuffle=True,
                         hue_aug=True,
                         random_crop_to_size=True)

# build network graph
data = dataset.get()

# build network
evaluation = tf.placeholder_with_default(True, shape=())
net = PoseEstimationNetwork()
hand_mask_pred = net.HandSegNet(data['image'], train=True)

# Start TF
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.8)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
tf.train.start_queue_runners(sess=sess)

# Loss
loss = 0.0
s = data['hand_mask'].get_shape().as_list()
for i, pred_item in enumerate(hand_mask_pred):
    gt = tf.reshape(data['hand_mask'], [s[0] * s[1] * s[2], -1])
    pred = tf.reshape(hand_mask_pred, [s[0] * s[1] * s[2], -1])
    loss += tf.reduce_mean(
        tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=gt))
# flag that allows to load a retrained snapshot(original weights used in the paper are used otherwise)
USE_RETRAINED = True
PATH_TO_SNAPSHOTS = './snapshots_posenet/'  # only used when USE_RETRAINED is true

# get dataset
dataset = BinaryDbReader(mode='evaluation',
                         shuffle=False,
                         hand_crop=True,
                         use_wrist_coord=False)

# build network graph
data = dataset.get()

# build network
evaluation = tf.placeholder_with_default(True, shape=())
net = PoseEstimationNetwork()
keypoints_scoremap = net.PoseNet(data['image_crop'])
keypoints_scoremap = keypoints_scoremap[-1]

# upscale to original size
s = data['image_crop'].get_shape().as_list()
keypoints_scoremap = tf.image.resize_images(keypoints_scoremap, (s[1], s[2]))

# Start TF
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.8)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
tf.train.start_queue_runners(sess=sess)

# initialize network weights
if USE_RETRAINED:
    # retrained version
    # images to be shown
    image_list = list()
    image_list.append('./data/1.png')
    image_list.append('./data/2.png')
    image_list.append('./data/3.png')
    image_list.append('./data/4.png')
    image_list.append('./data/5.png')

    # network input
    image_tf = tf.placeholder(tf.float32, shape=(1, 240, 320, 3))
    hand_side_tf = tf.constant([[1.0, 0.0]
                                ])  # left hand (true for all samples provided)
    evaluation = tf.placeholder_with_default(True, shape=())

    # build network
    net = PoseEstimationNetwork()
    hand_scoremap_tf = net.HandSegNet(image_tf)
    hand_scoremap_tf = hand_scoremap_tf[-1]

    # Start TF
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.8)
    sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))

    # initialize network
    # net.init(sess)
    # retrained version: HandSegNet
    last_cpt = tf.train.latest_checkpoint(PATH_TO_HANDSEGNET_SNAPSHOTS)
    assert last_cpt is not None, "Could not locate snapshot to load. Did you already train the network and set the path accordingly?"
    load_weights_from_snapshot(sess,
                               last_cpt,
                               discard_list=['Adam', 'global_step', 'beta'])
# get dataset
dataset = BinaryDbReader(mode='training',
                         batch_size=8,
                         shuffle=True,
                         hand_crop=True,
                         use_wrist_coord=False,
                         coord_uv_noise=True,
                         crop_center_noise=True,
                         crop_offset_noise=True,
                         crop_scale_noise=True)

# build network graph
data = dataset.get()

# build network
net = PoseEstimationNetwork()

# feed trough network
evaluation = tf.placeholder_with_default(True, shape=())
_, coord3d_pred, R = net.Pose3DNet(data['scoremap'], data['hand_side'],
                                   evaluation)

# Start TF
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.8)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
tf.train.start_queue_runners(sess=sess)

# Loss
loss = 0.0

loss += tf.reduce_mean(tf.square(coord3d_pred - data['keypoint_xyz21_can']))
from data.BinaryDbReaderSTB import *
from nets.network import PoseEstimationNetwork
from utils.general import EvalUtil, get_stb_ref_curves, calc_auc

# get dataset
# dataset = BinaryDbReader(mode='evaluation', shuffle=False, use_wrist_coord=False)
dataset = BinaryDbReaderSTB(mode='evaluation',
                            shuffle=False,
                            use_wrist_coord=False)

# build network graph
data = dataset.get()
image_scaled = tf.image.resize_images(data['image'], (240, 320))

# build network
net = PoseEstimationNetwork()

# feed through network
evaluation = tf.placeholder_with_default(True, shape=())
_, _, _, _, _, coord3d_pred = net.Pose3DNet(image_scaled, data['hand_side'],
                                            evaluation)
coord3d_gt = data['keypoint_xyz21']

# Start TF
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.8)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
tf.train.start_queue_runners(sess=sess)

# initialize network with weights used in the paper
net.init(sess,
         weight_files=[
Esempio n. 8
0
# flag that allows to load a retrained snapshot(original weights used in the paper are used otherwise)
USE_RETRAINED = False
PATH_TO_POSENET_SNAPSHOTS = './snapshots_posenet/'  # only used when USE_RETRAINED is true
PATH_TO_HANDSEGNET_SNAPSHOTS = './snapshots_handsegnet/'  # only used when USE_RETRAINED is true

# get dataset
dataset = BinaryDbReader(mode='evaluation',
                         shuffle=False,
                         use_wrist_coord=True,
                         scale_to_size=True)

# build network graph
data = dataset.get()

# build network
net = PoseEstimationNetwork()

# scale input to common size for evaluation
image_scaled = tf.image.resize_images(data['image'], (240, 320))
s = data['image'].get_shape().as_list()
scale = (240.0 / s[1], 320.0 / s[2])

hand_scoremap, image_crop, scale_crop, center = net.HandSegCrop(image_scaled)

# detect keypoints in 2D
s = image_crop.get_shape().as_list()
keypoints_scoremap = net.PoseNet(image_crop)
keypoints_scoremap = keypoints_scoremap[-1]
keypoints_scoremap = tf.image.resize_images(keypoints_scoremap, (s[1], s[2]))

# Start TF