} # 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))
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'])