Extraction and modification of intermediate layer outputs from pre-trained models and layer by layer inference

You could use this code as a template and add your manipulation instead of storing the activation in the dict.