def draw():
        figs = tfmpl.create_figures(2, figsize=(4, 3), dpi=100)

        figs[0].patch.set_facecolor('red')
        figs[1].patch.set_facecolor((0, 1, 0))

        return figs
Beispiel #2
0
    def attention_matplotlib(self, gen_images, gen_heatmaps, gen_vectormaps):
        '''
            Creates a matplotlib figure and writes it to tensorboard using tf-matplotlib
            gen_images: The image tensor of shape (batchsize,width,height,channels) you want to write to tensorboard
            '''
        r, c = 2, 5  # want to write 25 images as a 5x5 matplotlib subplot in TBD (tensorboard)
        figs = tfmpl.create_figures(1, figsize=(10, 15))
        cnt = 0
        for idx, f in enumerate(figs):
            for i in range(r):
                for j in range(c):
                    ax = f.add_subplot(r, c, cnt + 1)
                    ax.set_yticklabels([])
                    ax.set_xticklabels([])
                    #import pdb;pdb.set_trace()
                    img_shape = gen_images[0][cnt].shape
                    hmps = np.squeeze(gen_heatmaps[cnt])
                    hmps = cv2.resize(hmps, (0, 0),
                                      fx=8,
                                      fy=8,
                                      interpolation=cv2.INTER_CUBIC)
                    hmp = cv2.resize(hmps, (img_shape[1], img_shape[0]),
                                     interpolation=cv2.INTER_CUBIC)
                    ax.imshow(gen_images[0][cnt])
                    ax.imshow(hmp[:, :, cnt % 5], alpha=0.5)
                    #ax.imshow(hmp[:,:,1],alpha=0.5)
                    #ax.imshow(hmp[:,:,2],alpha=0.5)
                    #ax.imshow(hmp[:,:,3],alpha=0.5)
                    #ax.imshow(hmp[:,:,4],alpha=0.5)
                    # writes the image at index cnt to the 5x5 grid

                    cnt += 1
            f.tight_layout()
        return figs
Beispiel #3
0
    def draw(images):
        num_figs = len(images)

        height = math.ceil(num_figs / 2)

        # draw figures in two column
        fig = tfmpl.create_figures(1,
                                   figsize=(12.8 if num_figs > 1 else 6.4,
                                            4.8 * height))[0]

        # pdb.set_trace()
        for i in range(height):
            for j in range(2):
                seq = i * 2 + j + 1
                if seq > num_figs:
                    fig.tight_layout()
                    return fig

                if num_figs == 1:
                    ax = fig.add_subplot(1, 1, 1)
                else:
                    ax = fig.add_subplot(height, 2, seq)

                ax = fig.add_subplot(height, 2, seq)
                ax.axis('off')
                ax.imshow(images[seq - 1]['data'])
                ax.set_title(images[seq - 1]['title'], fontsize=24)

        fig.tight_layout()

        return fig
Beispiel #4
0
def plotWave(audioTensor):
    """ Plots audio to a wave graph """
    figs = tfmpl.create_figures(BATCH_SIZE)
    for i, f in enumerate(figs):
        sp = f.add_subplot(111)
        sp.plot(audioTensor[i, :, :])

    return figs
Beispiel #5
0
        def draw_scatter(scaled, colors):
            '''Draw scatter plots. One for each color.'''
            figs = tfmpl.create_figures(len(colors), figsize=(4, 4))
            for idx, f in enumerate(figs):
                ax = f.add_subplot(111)
                ax.axis('off')
                ax.scatter(scaled[:, 0], scaled[:, 1], c=colors[idx])
                f.tight_layout()

            return figs
Beispiel #6
0
def plotSpec(audioTensor):
    """ Plots audio to a wave graph """
    figs = tfmpl.create_figures(BATCH_SIZE)
    for i, f in enumerate(figs):
        sp = f.add_subplot(111)
        dim = audioTensor[i, :, :]
        dim = np.squeeze(dim)
        sp.specgram(x=dim, NFFT=256, Fs=2)

    return figs
def tf_keypoint_summary(points):
    # points is BxNx2
    batch_size = points.shape[0]
    figs = tfmpl.create_figures(batch_size, figsize=(4,4))
    try:
        for idx, f in enumerate(figs):
            ax = f.add_subplot(111)
            ax.scatter(points[idx, :, 0], points[idx, :, 1], c='b')
            f.tight_layout()
    except Exception as ex:
        print('-------------')
        print('--- error ---')
        print('-------------')
        print('keypoint summary exception:', ex)
        # pdb.set_trace()

    return figs
Beispiel #8
0
    def draw(images):
        num_figs = len(images)
        fig = tfmpl.create_figures(1, figsize=(12.8, 12.8))[0]

        # pdb.set_trace()
        for i in range(rows):
            for j in range(cols):
                seq = i * cols + j + 1
                if seq > num_figs:
                    fig.tight_layout()
                    return fig

                if num_figs == 1:
                    ax = fig.add_subplot(1, 1, 1)
                else:
                    ax = fig.add_subplot(rows, cols, seq)

                ax.axis('off')
                ax.imshow(images[seq - 1, ...])

        fig.tight_layout()
        return fig
Beispiel #9
0
            def draw_line(measured_rt, predicted_rt):
                fig = tfmpl.create_figures(1, figsize=(16, 8))[0]

                ax = fig.add_subplot(1, 2, 1)
                for item in ([ax.title, ax.xaxis.label, ax.yaxis.label] + \
                    ax.get_xticklabels() + ax.get_yticklabels()):
                    item.set_fontsize(20)

                # ax.axis('off')
                ax.plot(measured_rt['index'], measured_rt['value'], 'b')
                ax.set_title(measured_rt['title'], fontsize=24)

                ax = fig.add_subplot(1, 2, 2)
                for item in ([ax.title, ax.xaxis.label, ax.yaxis.label] + \
                    ax.get_xticklabels() + ax.get_yticklabels()):
                    item.set_fontsize(20)

                ax.plot(predicted_rt['index'], predicted_rt['value'], 'r')
                ax.set_title(predicted_rt['title'], fontsize=24)

                fig.tight_layout()

                return fig