예제 #1
0
        
            # calculate mpjpe for each image
            scoreR = mpjpe(predR*img.shape[-1], keypoints*img.shape[-1], weights, dist)[0]
            scoreR = str(np.round(scoreR, 2))
            scoreS = mpjpe(predS*img.shape[-1], keypoints*img.shape[-1], weights, dist)[0]
            scoreS = str(np.round(scoreS, 2))
            print("MPJPE  for image {}: regression {}, softargmax {}".format(idx, scoreR, scoreS))
        
            # show results
            img_np = np.transpose(img.cpu().detach().numpy(), [0, 2, 3, 1])
            img_np = np.round((img_np + 1.0) * 127.5).astype(np.uint8)
            kp_pred_R = predR.cpu().detach().numpy().reshape([-1, 17, 2])
            kp_pred_S = predS.cpu().detach().numpy().reshape([-1, 17, 2])
            kp_gt = keypoints.cpu().detach().numpy().reshape([-1, 17, 2])
            vis = weights.cpu().detach().numpy().reshape([-1, 17])
        
            for bid in range(img_np.shape[0]):
                fig = plt.figure()
                ax1 = fig.add_subplot(131)
                ax2 = fig.add_subplot(132)
                ax3 = fig.add_subplot(133)
                ax1.imshow(img_np[bid]), ax1.axis('off'), ax1.set_title('ground truth', fontdict={'fontsize':10})
                plot_keypoints(ax1, kp_gt[bid], vis[bid], img_size=img_np[bid].shape[:2], draw_limbs=True, draw_kp=True)
                ax2.imshow(img_np[bid]), ax2.axis('off'), ax2.set_title('regression \n (MPJPE:'+scoreR+')', fontdict={'fontsize':10})
                plot_keypoints(ax2, kp_pred_R[bid], vis[bid], img_size=img_np[bid].shape[:2], draw_limbs=True, draw_kp=True)
                ax3.imshow(img_np[bid]), ax3.axis('off'), ax3.set_title('softargmax \n (MPJPE:'+scoreS+')', fontdict={'fontsize':10})
                plot_keypoints(ax3, kp_pred_S[bid], vis[bid], img_size=img_np[bid].shape[:2], draw_limbs=True, draw_kp=True)
                # plt.figtext(0.5, 0.1, "MPJPE: "+str(score), wrap=True, horizontalalignment='center', fontsize=12)
                plt.savefig('example.png', bbox_inches='tight')
                plt.show()
예제 #2
0
import matplotlib.pyplot as plt
import numpy as np

from model.data import get_data_loader
from utils.plot_util import plot_keypoints


if __name__ == '__main__':
    """
        Script to show samples of the dataset
    """
    reader = get_data_loader()

    for idx, (img, keypoints, weights) in enumerate(reader):
        print('img', type(img), img.shape)
        print('keypoints', type(keypoints), keypoints.shape, keypoints)
        print('weights', type(weights), weights.shape, weights)

        # turn image tensor into numpy array containing correctly scaled RGB image
        img_rgb = ((np.array(img) + 1.0)*127.5).round().astype(np.uint8).transpose([0, 2, 3, 1])

        # show
        plt.figure()
        plt.imshow(img_rgb[0]); plt.axis('off'); ax = plt.gca()
        plot_keypoints(ax, keypoints[0], weights[0], draw_limbs=True, draw_kp=True)
        plt.show()