philipperemy/keract

display_heatmaps does not work with single-channel prediction

jonashaag opened this issue · 6 comments

If your prediction results has only 1 channel, then the .subplots() call will not return an object that has the .flat attribute, so the function will fail with an AttributeError.

Same thing for display_activations. Here's some code that fixes a single layer's activation info:

def fix_activation_shape(acts, name):
    # Fix something else: keras layers not having implicit batch_size parameter in shape
    fixed = np.reshape(acts[name], (1, *acts[name].shape))
    # Work around this (keract#84) by duplicating single channel
    fixed = np.concatenate([fixed, fixed], axis=-1)
    return {**acts, name: fixed}

@jonashaag do you have an example where I can reproduce the bug?

acts = {'1_channel': np.random.uniform(size=(1, 32, 32, 1))}
display_activations(acts, save=True)

When I run this dummy example it seems to work properly (1 channel).

Thanks!

Edit: my comment doesn’t make sense. I’ll try to come up with minimal example.

@jonashaag thank youu

@jonashaag you have an example? I'll close the issue otherwise.

Haven’t used the tool since then so no. I’ll respond here if it the issue happens again.