def vis_all_joints(img: PIL, output, figsize=(8, 8), save_filename=None):
    fig = plt.figure(figsize=figsize)
    H, W = output[0].shape
    plt.imshow(img.resize((W, H)), cmap='gray', interpolation='bicubic')
    joints = np.clip(output, 0.4, 1.0)
    joint_sum = np.sum(output, axis=0)  # stacking all layers
    plt.imshow(joint_sum, alpha=0.5, cmap='jet', interpolation='bicubic')
    plt.axis('off')

    if save_filename:
        fig.savefig(save_filename)
    return
Example #2
0
    def _pre_process_image(self, img: PIL):
        img = img.resize((self.run_parameters.get('input_shape')[0],
                          self.run_parameters.get('input_shape')[1]),
                         Image.ANTIALIAS)
        if self.run_parameters.get('greyscale'):
            img = img.convert.convert('LA')
        else:
            img = img.convert('RGB')
        img = np.array(img)
        img = img / 255
        # casts list to tuple
        img_shape = (1, ) + tuple(self.run_parameters.get('input_shape'))

        img = img.reshape(img_shape)
        return img
def vis_joints(img: PIL, output, save_filename=None):
    fig = plt.figure(figsize=(16, 16))
    for idx, joint_data in enumerate(output):
        ax = fig.add_subplot(4, 4, idx + 1, xticks=[], yticks=[])
        plt.title(f'{idx}: {JOINT_NAMES[idx]}')
        H, W = joint_data.shape
        plt.imshow(img.resize((W, H)), cmap='gray', interpolation='bicubic')
        plt.imshow(
            joint_data,
            alpha=0.5,
            cmap='jet',
        )
        plt.axis('off')

    if save_filename:
        fig.savefig(save_filename)
    return
def transform_image(img: PIL):
    img = img.resize((256, 256), PIL.Image.BICUBIC)  # resizing image
    img = np.asarray(img)

    # converting from HWC to CHW format
    img_chw = HWC_2_CHW(img)

    # Convert image to floating point in the range 0 to 1
    img_chw = np.float32(img_chw) / 255.0

    # Normalizing image data
    means, stds = [0.485, 0.456, 0.406], [0.229, 0.224, 0.225]

    img_chw = img_normalize(img_chw, means, stds)

    img_chw = np.expand_dims(img_chw, axis=0)  # Making batch size of 1

    return img_chw