philipperemy / keract

Layers Outputs and Gradients in Keras. Made easy.
MIT License
1.04k stars 185 forks source link

AttributeError: 'AxesSubplot' object has no attribute 'flat' #105

Closed venergiac closed 4 years ago

venergiac commented 4 years ago

I applied keract to my VQ-VAE

on

kt.display_heatmaps(activations, img_o, save=False)

I got

AttributeError: 'AxesSubplot' object has no attribute 'flat'

but kt.display_actovations(activations, save=False)

worked well.

I used VGG16 and keract worked well for both cases.

I solved changing the keract

def display_heatmaps(activations, input_image, directory='.', save=False, fix=True):

      if hasattr(axes,'flat'):
                axes.flat[i].imshow(input_image / 255.0)

                axes.flat[i].imshow(img, alpha=0.3, cmap='jet', interpolation='bilinear')
            else:
                axes.imshow(input_image / 255.0)
                axes.imshow(img, alpha=0.3, cmap='jet', interpolation='bilinear')
        if hasattr(axes,'flat'):
            axes.flat[i].axis('off')
        else:
            axes.axis('off')

but it is a workaround

philipperemy commented 4 years ago

@venergiac thanks for reporting. I'm going to see if there's a better way to handle this.

philipperemy commented 4 years ago

Do you have a snippet that reproduces the problem? I can't reproduce it on a toy example. Thanks!

philipperemy commented 4 years ago

I could reproduce the error. I guess this workaround works just fine for now. I'll push that to the codebase and will update it later when I have more time to understand exactly what's going on.

philipperemy commented 4 years ago

Fixed in https://github.com/philipperemy/keract/commit/48ebbc7ac13e1a104eafe3ce7fd799d361664a1e

philipperemy commented 4 years ago

Released in 4.2.2

venergiac commented 4 years ago

yes confirmed now it works