'Get layer activations'

def get_layer_acts(self, callback_data, model, x, batch_ind):

    imgs_to_store = set()
    for (l, lyr) in enumerate(model.layers.layers, 0):
        x = lyr.fprop(x, inference=True)
        if (not isinstance(lyr, Convolution)):
            continue
        (num_fm, H, W) = lyr.out_shape
        fm_argmax = self.be.zeros((num_fm, 1), dtype=np.int32)
        maxact_idx = self.be.array((((np.arange(num_fm) * H) * W) * self.be.bsz), dtype=np.int32)
        act_data = callback_data['deconv/max_act/{0:04}'.format(l)]
        all_acts = lyr.outputs.reshape((num_fm, ((H * W) * self.be.bsz)))
        all_acts_flat = lyr.outputs.reshape((((num_fm * H) * W) * self.be.bsz))
        fm_argmax[:] = self.be.argmax(all_acts, axis=1)
        maxact_idx[:] = (maxact_idx + fm_argmax)
        acts_host = all_acts_flat[maxact_idx].get()
        fm_argmax_host = fm_argmax.get()
        num_fm_vis = min(num_fm, self.max_fm)
        for fm in range(num_fm_vis):
            argmax = fm_argmax_host[fm]
            img_ind = int((argmax % self.be.bsz))
            curr_max_act = acts_host[fm]
            if (curr_max_act > act_data['activation'][fm]):
                act_data['activation'][fm] = curr_max_act
                act_data['batch_img'][fm] = (batch_ind, img_ind)
                act_data['fm_loc'][fm] = (argmax // self.be.bsz)
                imgs_to_store.add(img_ind)
    return list(imgs_to_store)
