def get_dataflow(path, is_train): ds = SynthHands(path, is_train) # read data from lmdb if is_train: ds = MapData(ds, read_image_url) ds = MapData(ds, pose_to_img) ds = PrefetchData(ds, 1000, multiprocessing.cpu_count() * 1) else: ds = MultiThreadMapData(ds, num_thread=16, map_func=read_image_url, buffer_size=1000) ds = MapData(ds, pose_to_img) ds = PrefetchData(ds, 100, multiprocessing.cpu_count() // 4) return ds
last_gs_num2 = gs_num sample_image = [enqueuer.last_dp[0][i] for i in range(4)] outputMat = sess.run(outputs, feed_dict={ q_inp: np.array((sample_image + val_image) * max(1, (args.batchsize // 8))) }) heatMat = outputMat[:, :, :, :19] sample_results = [] for i in range(len(sample_image)): test_result = SynthHands.display_image(sample_image[i], heatMat[i], as_numpy=True) test_result = cv2.resize(test_result, (640, 640)) test_result = test_result.reshape([640, 640, 3]).astype(float) sample_results.append(test_result) test_results = [] for i in range(len(val_image)): test_result = SynthHands.display_image( val_image[i], heatMat[len(sample_image) + i], as_numpy=True) test_result = cv2.resize(test_result, (640, 640)) test_result = test_result.reshape([640, 640, 3]).astype(float)
def _get_dataflow_onlyread(path, is_train): ds = SynthHands(path, is_train) # read data from lmdb ds = MapData(ds, read_image_url) ds = MapData(ds, pose_to_img) # ds = PrefetchData(ds, 1000, multiprocessing.cpu_count() * 4) return ds
return [ meta_l[0].img.astype(np.float16), meta_l[0].get_heatmap(target_size=(_network_w // _scale, _network_h // _scale)) ] if __name__ == '__main__': os.environ['CUDA_VISIBLE_DEVICES'] = '' # df = get_dataflow('/data/public/rw/coco/annotations', True, '/data/public/rw/coco/') df = _get_dataflow_onlyread('/home/marcelo/hands/hand_labels_synth', True) # df = get_dataflow('/root/coco/annotations', False, img_path='http://gpu-twg.kakaocdn.net/braincloud/COCO/') from tensorpack.dataflow.common import TestDataSpeed TestDataSpeed(df).start() with tf.Session() as sess: df.reset_state() t1 = time.time() for idx, dp in enumerate(df.get_data()): if idx == 0: for d in dp: logger.info('%d dp shape={}'.format(d.shape)) print(time.time() - t1) t1 = time.time() SynthHands.display_image(dp[0], dp[1].astype(np.float32)) pass logger.info('done')
print( "Belief maps for last stage, one for each keypoint plus and additional one for the background" ) fig, ax = plt.subplots(nrows=5, ncols=5) index = 0 for row in ax: for col in row: col.imshow(last_stage[:, :, index]) index += 1 if index >= 22: break plt.show() print("Draws last stage belief maps on top of image") test_result = SynthHands.display_image(img, last_stage, as_numpy=True) test_result = cv2.cvtColor(test_result, cv2.COLOR_RGB2BGR) cv2.imshow("Belief Maps", test_result) cv2.waitKey(0) print("Draws each stage belief maps") fig = plt.figure() for i, stage_out in enumerate(stages_outs): stage_out = stage_out[0] a = fig.add_subplot(3, 2, i + 1) a.set_title('Stage #{}'.format(i + 1)) plt.imshow(SynthHands.get_bgimg(img, target_size=(stage_out.shape[1], stage_out.shape[0])), alpha=0.5) tmp = np.amax(stage_out, axis=2)