SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Most exciting images We apply EGG diffusion to characterize the properties of neurons in macaque area V4. For each of these experiments, we use the pre-trained ADM diffusion model trained on  $256 \times 256$  ImageNet images from Dhariwal and Nichol [53]. In each of our experiments, we consider two paradigms: 1) within architecture, where we use two independently pre-trained ensembles containing 5 models of the same architecture (Gaussian model or Attention model). We generate images on one and evaluate them on the other. 2) cross architecture, two independently pre-trained ensembles containing 5 models of different architectures (Gaussian model and Attention model). We demonstrate EGG on three tasks ① Most Exciting Input (MEI) generation, where the generation method needs to generate an image that maximally excites an individual neuron, ② naturalistic image generation, where a natural-looking image is generated that maximizes individual neuron responses, and ③ reconstruction of the input image from predicted neuronal responses. Running the experiments required a total of 7 GPU days. All computations were performed on a single consumer-grade GPU: NVIDIA GeForce RTX 3090 or NVIDIA GeForce RTX 2080 Ti depending on the availability.
MEIs have served as a powerful tool for visualizing features of a network, providing insights and testable predictions [17-21, 23, 66]. For the generation of MEIs, we selected 90 units at random from a subset of all 1,244 for which both the Gaussian model and the Attention model achieve at least a correlation of 0.5 to the average responses across repeated presentations. We compare our method to a vanilla gradient ascent (GA) method [24] which optimizes the pixels of an input image  $\mathbf{x}$  to obtain the maximal response of the selected neuron. For the GA method, we use Gaussian blur preconditioning of the gradient. The stochastic gradient descent (SGD) optimizer was used with a learning rate of 10 and the image was optimized for 1,000 steps. We also evaluated other setups for the GA method without finding major differences (see Fig. S2). We define EGG diffusion with the energy function  $E(\bar{\boldsymbol{x}}_0) = f_i(\bar{\boldsymbol{x}}_0)$ , where  $f_{i}$  is the  $i$ -th neuron model and  $\bar{\boldsymbol{x}}_0$  is the estimated clean sample. We optimize MEIs for both the Gaussian model and the Attention model. We set the energy scale to  $\lambda = 10$  for the Gaussian model and  $\lambda = 5$  for the Attention model.  $\lambda$  was chosen via a grid search, for more details refer to Fig. 5B. The diffusion process was run for 100 respaced time steps for the Gaussian model and 50 respaced time steps for the Attention model. For both EGG and GA, we set the norm of the  $100 \times 100$  image to a fixed value of 25. For each of the methods, we chose
Figure 3: a) Examples of MEIs optimized using EGG diffusion and GA for macaque V4 Gaussian and Attention models. b) Comparison of activations for different neurons between EGG diffusion and GA on the Within and Cross Architecture validation paradigms. Line fits obtained via Huber regression with  $\varepsilon = 1.1$ . Curated image selection to show various properties of the neurons like fur, eyes, curves and edges.
the best of 3 MEIs optimized from different seeds. We show the influence of the initial seed on the generated MEI in figure S3. Furthermore, the images that are generated by the ADM model are RGB. We show examples of the color outputs in figure S4.
We show some examples of MEIs generated with EGG diffusion and GA for the two architectures in figure 3A. For more examples, refer to the supplementary materials figure S5. We find that the EGG-generated MEIs are significantly better (Attention) or similarly (Gaussian) activating within architectures and are significantly better at generalizing across architectures (Fig. 3B).
This can also be observed by a significant increase in the mean activation across all units (Table 2). Perceptually, EGG-generated MEIs of the Attention model looked more complex and natural than the GA-generated MEIs, and more similar to MEIs of the Gaussian model pre-trained on natural image classification.
Comparing EGG-based MEIs to the ones found by Willeke et al. [24] using GA, we find that the preferred image feature is usually preserved, but MEIs generated for the Attention model are in most cases smaller in visual angle than their Gaussian model counterparts (Fig. S5). To quantify that the MEIs from the Attention model are smaller we compute an isotropic Gaussian envelope for the MEIs. We find that the Attention model generates MEIs for which their Gaussian envelope on average is smaller than for the Gaussian MEIs ( $\sigma_{At} = 49.62$  vs  $\sigma_{Ga} = 55.36$ , Wilcoxon signed rank test p-value: 0.0078).
Finally, EGG diffusion is almost 4.7-fold faster than GA, requiring only on average 46s per MEI in comparison to the required
219s for the GA method (Fig. 4) on a single NVIDIA GeForce RTX 3090 across 10 repetitions. This
Figure 4: Mean comparison of the generation times between the EGG and GA (error bars denote standard error).
Paradigm	Within (Gaussian)	Cross (Gaussian)	Within (Attention)	Cross (Attention)
Gradient Ascent	11.43	5.51	7.59	4.42
EGG Diffusion	11.76	6.53†	10.56†	5.50†
Table 2: Comparison of the average unit activations in response to MEIs in two paradigms 1) within architectures and 2) cross architectures, for two architectures Gaussian and Attention. Bold marks the method which has higher mean activation, and the  $\dagger$  marks the increases which are statistically significant (Wilcoxon signed-rank test, respective p-values:  $0.08$ ,  $2.87\cdot 10^{-6}$ ,  $2.84\cdot 10^{-10}$ ,  $4.39\cdot 10^{-5}$ ). The architecture in the bracket indicates the generator architecture.
Figure 5: a) Examples of MENIs optimized using EGG diffusion in the macaque V4 for different neurons and different energy scales  $\lambda \in \{1,2,5,10\}$ . b) Mean and standard error of the activations of neurons across different energy scales normalized by the activation of the GA MEI. c) FID between MEIs across energy scales and top-5 activating ImageNet images.
is a substantial gain, as Willeke et al. [24] required approximately 1.25 GPU years to optimize the MEIs presented in their study. With EGG, only approximately 0.25 GPU years would be needed to produce the results of the study, while providing higher quality and higher resolution MEIs. Thus, EGG can provide major savings in time and energy, and improve the quality of MEIs.
Controlling the "naturalness" to generate most exciting natural images Unlike GA, EGG can also be used to synthesize more natural-looking stimuli by controlling the energy scale hyperparameter  $\lambda$ . Changing the value of  $\lambda$  trades off the importance of the maximization property of the image and its "naturalness". To demonstrate this, we generated images for 150 neurons with the highest correlations to the average for the Gaussian model. We used energy scales  $\lambda \in \{1,2,5,10\}$ , fixed the  $100 \times 100$  image norm to 50, and used 50 steps re-spaced from 1000. Each image was generated using 3 different seeds and the best-performing image on the generator model was selected.
We show examples of the generated images across different energy scales in figure 5A for both the Gaussian model and the Attention model. For more examples, refer to the supplementary material (Fig. S6, Fig. S7). We subsequently quantified the predicted responses across different values of  $\lambda$ . We find that increasing  $\lambda$  increases the predicted responses (Fig. 5B), however, at higher  $\lambda$  values
Figure 6: a) Schematic of the reconstruction paradigm. The generated image is compared to the ground truth image via  $L_{2}$  distance in the unit activations space. Reconstructed images from 1,244 units. b)  $L_{2}$  distances in the unit activations space for the Within and Cross architecture domains comparing the EGG and GD generation methods. Shows that the EGG method generalizes better than GD across architectures. c) examples of reconstructions generated by EGG and GD in comparison to the ground truth (GT). d) Survey results on 45 voluntary human participants. Indicates that in  $84\%$  of images, the participants preferred the EGG generated reconstructions with a rate  $\geq 0.6$ .
the responses begin to plateau, or even decrease. Therefore, for generating MEIs, we use  $\lambda = 10$  for the Gaussian model and  $\lambda = 5$  for the Attention model. It can be further observed that decreasing  $\lambda$  increases the naturalness of the generated image while preserving the features of the image that the neuron is tuned towards. To quantify the increase in the naturalness of the MEIs across  $\lambda$ s, we measured the FID score between the generated images at different  $\lambda$  values and the top-5 ImageNet images (Fig. 5C). Our results show that by changing  $\lambda$  we approach the natural images manifold (lower FID). We also find that EGG generates MEIs ( $\lambda = 1$ ) similarly activating to the top-1 Imagenet images (Fig. S8).
Image reconstruction from unit responses Another application of EGG diffusion is image reconstruction from neuronal responses. A similar task has been attempted with success using diffusion models from human fMRI data [34, 35]. Given that only a small fraction of neurons were recorded, the image is encoded in an under-complete, significantly lower-dimensional space. Therefore, it is to be expected that the reconstructed image  $\pmb{x}$  will not necessarily be equal to the ground truth image  $\pmb{x}_{gt}$ . However, a better reconstruction  $\pmb{x}^*$  is one that generalizes across models. Therefore, regardless of the model  $f$  used, we should get  $||f(\pmb{x}^{*}) - f(\pmb{x}_{gt})||_{2} = 0$ . This is trivially true for  $\bar{x}_0 = x_{gt}$  but, given the complexity of the model, there are likely other solutions. We therefore consider a masked version of the reconstructions for visualization. We mask the reconstructions to the joint receptive field of all 1,244 neurons. The mask is obtained by computing the average absolute gradients  $\mathrm{mask} = \mathbb{E}_x[|\nabla_xf(x)|]$  across the responses to the test images. The masks were normalized to be between 0 and 1 and the values below 0.25 are clamped to 0.
We can reconstruct images in the EGG framework by defining the energy function as an  $L_{2}$  distance between the predicted responses to the ground truth image  $f(\pmb{x}_{gt})$  and the predicted responses to a generated image (Fig. 6A)  $E(\pmb{x}) = ||f(\pmb{x}) - f(\pmb{x}_{gt})||_{2}$ . Note that, instead of  $f(\pmb{x}_{gt})$ , we could also use recorded neuronal responses. The images are generated from the Gaussian model with  $\lambda = 2$  and 1000 timesteps, with the norm of the  $100 \times 100$  image fixed to 60. We compare EGG to a gradient descent (GD) method that simply minimizes the L2 distance. The GD uses an AdamW optimizer with a learning rate of 0.05. In GD, at each optimization step the image  $\pmb{x}_t$  is Gaussian blurred and the norm is set to 60 before passing it to the neural encoding model. We optimize the GD reconstruction up to the point where the train  $L_{2}$  distance is matched between the GD and the EGG for a fair comparison of the generalization capabilities. We verified that the GD images do not improve qualitatively with more optimization steps (Fig. S9). We find that when generating the reconstruction using EGG diffusion we obtain 1) comparable within-architecture generalization and 2) much better cross-architecture generalization (Fig. 6B). The EGG-generated images produce lower within architecture distances for  $84\%$  of the images and for  $98\%$  in the cross-architecture case.
We show examples of EGG diffusion and GD reconstructions in Fig. 6C. Qualitatively, the images optimized by EGG resemble the ground truth image much more faithfully than the GD images. More examples are available in the supplementary materials (Fig. S10) and for reconstructions from the attention model see figure S11. We furthermore reconstruct images from real neurons by minimizing the distance between the model responses and recorded average neural responses to the image (Fig. S12).
Human perceptual evaluation As shown in Cobos et al. [67], metrics like SSIM are not necessarily a good predictor of how well neuronal responses are reproduced in vivo. Therefore, we conducted a voluntary anonymous survey with 45 voluntary participants on 50 test images (Fig. S13). The participants were instructed to choose which image (GD optimized or EGG generated) was more similar to the ground truth image. Results show an  $82.22\%$  average preference for EGG-generated images (95% confidence interval [80.59%, 83.75%]; Wilson score interval). In  $84\%$  of the images, the EGG method was preferred more than  $60\%$  of the time (Fig. 6D).
Limitations While EGG diffusion on average performs better than GA, it does come with limitations. Firstly, It is important to note that the results shown in this study have not been verified in vivo. Moreover, while the energy scale provides additional flexibility, it is important to keep it mind that it is an additional hyperparameter that needs to be selected to obtain the desired results, for which careful controls are necessary before the method can be used for in-vivo verification. For example, if the energy scale is too high, our method can be unreliable, which we identified in 3 out of 90 cases where EGG diffusion failed to provide a satisfactory result with the Gaussian model (Fig. 7). Furthermore, the parameter value also does not necessarily represent the same value across energy functions. Another limitation is that the maximal number of steps to generate the sample is constricted by the pre-trained diffusion model, i.e. at most 1000 steps can be used. In addition, the encoding model needs to generalize to the
Figure 7: Examples of failure cases in comparison to the gradient ascent method. The text shows the predicted response rate by the within-architecture validation.
manifold of the diffusion model. Finally, since neurons are strongly driven by contrast, encoding models often tend to push generated images to very high contrast values. To avoid this effect and make the model focus on the image content, we evaluate the energy guiding encoding model at a normalized image to eliminate the contrast direction from the guidance. This can be seen as an additional prior.
In this study, we introduced a new model architecture, called the attention readout, for predicting the activity of neurons in macaque area V4 , which together with a fully data-driven convolutional core outperforms previous task-driven models. Furthermore, we propose a novel method for synthesizing images based on guiding diffusion models via energy functions (EGG). Our results indicate that EGG diffusion produces most exciting inputs (MEIs) which generalize better across architectures than the previous standard gradient ascent (GA) method. In addition, EGG diffusion significantly reduces compute time enabling larger-scale synthesis of visual stimuli. EGG diffusion is not limited to the generation of MEIs and, within the same framework, allows, among other characterizations, to 1) generate most exciting naturalistic images which approach the manifold of most activating images in the ImageNet database, and 2) reconstruct images from unit responses, which generalize better across architectures and qualitatively resemble more the original image than images obtained via regular gradient descent optimization. While the dataset we use for this study was recorded from the macaque visual cortex, it is in principle possible to use EGG for MEI generation and reconstructions with calcium imaging similar to the GA method on two-photon data in Walker et al. [17]. In fact, EGG can be applied to any modality that yields an encoding model and where a suitable diffusion model is available. More generally, EGG can be used whenever the "constraint" on a particular image can be phrased in terms of an energy function. In summary, EGG diffusion provides a flexible and powerful framework for studying coding properties of the visual system.
The authors thank the International Max Planck Research School for Intelligent Systems (IMPRS-IS) for supporting Konstantin Willeke and Arne Nix. The authors also thank Mohammad Bashiri and Suhas Shirinvasan for their technical support and helpful discussions. The research was supported by the Cyber Valley Research Fund (AN, FHS). FHS is further supported by the German Federal Ministry of Education and Research (BMBF) via the Collaborative Research in Computational Neuroscience (CRCNS) (FKZ 01GQ2107), as well as the Collaborative Research Center (SFB 1233, Robust Vision). PP is supported by the German Federal Ministry for Economic Affairs and Climate Action (FKZ ZF4076506AW9). We also acknowledge support from the National Institute of Mental Health and National Institute of Neurological Disorders And Stroke under Award Number U19MH114830 and National Eye Institute award numbers R01 EY026927 and Core Grant for Vision Research T32-EY-002520-37 as well as the National Science Foundation Collaborative Research in Computational Neuroscience, USA with grant number IIS-2113173, Germany with FKZ: 01GQ2107. We thank our lab members, family, and friends for participating in the anonymous survey.
[1] D H Hubel and T N Wiesel. Receptive fields of single neurones in the cat's striate cortex. J. Physiol., 148(3):574-591, October 1959.
[2] Charles F Cadieu, Ha Hong, Daniel L K Yamins, Nicolas Pinto, Diego Ardila, Ethan A Solomon, Najib J Majaj, and James J DiCarlo. Deep neural networks rival the representation of primate IT cortex for core visual object recognition. PLoS Comput. Biol., 10(12):e1003963, December 2014.
[3] Daniel L K Yamins, Ha Hong, Charles F Cadieu, Ethan A Solomon, Darren Seibert, and James J DiCarlo. Performance-optimized hierarchical models predict neural responses in higher visual cortex. Proc. Natl. Acad. Sci. U. S. A., 111(23):8619–8624, June 2014.
[4] Santiago A Cadena, George H Denfield, Edgar Y Walker, Leon A Gatys, Andreas S Tolias, Matthias Bethge, and Alexander S Ecker. Deep convolutional models improve predictions of macaque V1 responses to natural images. PLoS Comput. Biol., 15(4):e1006897, April 2019.
[5] Fabian H Sinz, Alexander S Ecker, Paul G Fahey, Edgar Y Walker, Erick Cobos, Emmanouil Froudarakis, Dimitri Yatsenko, Xaq Pitkow, Jacob Reimer, and Andreas S Tolias. Stimulus domain transfer in recurrent models for large scale cortical population prediction on video. In Proceedings of the 32nd International Conference on Neural Information Processing Systems, NIPS'18, pages 7199-7210, Red Hook, NY, USA, December 2018. Curran Associates Inc.
[6] Yimeng Zhang, Tai Sing Lee, Ming Li, Fang Liu, and Shiming Tang. Convolutional neural network models of V1 responses to complex patterns. J. Comput. Neurosci., 46(1):33-54, February 2019.
[7] Lane T McIntosh, Niru Maheswaranathan, Aran Nayebi, Surya Ganguli, and Stephen A Baccus. Deep learning models of the retinal response to natural scenes. In Proceedings of the 30th International Conference on Neural Information Processing Systems, NIPS'16, pages 1369-1377, Red Hook, NY, USA, December 2016. Curran Associates Inc.
[8] David A Klindt, Alexander S Ecker, Thomas Euler, and Matthias Bethge. Neural system identification for large populations separating "what" and "where". November 2017.
[9] William F Kindel, Elijah D Christensen, and Joel Zylberberg. Using deep learning to probe the neural code for images in primary visual cortex. J. Vis., 19(4):29, April 2019.
[10] Alexander S Ecker, Fabian H Sinz, Emmanouil Froudarakis, Paul G Fahey, Santiago A Cadena, Edgar Y Walker, Erick Cobos, Jacob Reimer, Andreas S Tolias, and Matthias Bethge. A rotation-equivariant convolutional neural network model of primary visual cortex. September 2018.
[11] Benjamin R Cowley and Jonathan W Pillow. High-contrast "gaudy" images improve the training of deep neural network models of visual cortex. June 2020.
[64] Zahra Kadkhodaie and Eero P Simoncelli. Solving linear inverse problems using the prior implicit in a denoiser. July 2020.
[65] Berthy T Feng, Jamie Smith, Michael Rubinstein, Huiwen Chang, Katherine L Bouman, and William T Freeman. Score-Based diffusion models as principled priors for inverse imaging. April 2023.
[66] Jiakun Fu, Konstantin F Willeke, Pawel A Pierzchlewicz, Taliah Muhammad, George H Denfield, Fabian Hubert Sinz, and Andreas S Tolias. Heterogeneous orientation tuning across Sub-Regions of receptive fields of V1 neurons in mice. February 2022.
[67] Erick Cobos, Taliah Muhammad, Paul G Fahey, Zhiwei Ding, Zhuokun Ding, Jacob Reimer, Fabian H Sinz, and Andreas S Tolias. It takes neurons to understand neurons: Digital twins of visual cortex synthesize neural metamers. December 2022.
[68] Jia Deng, Wei Dong, Richard Socher, Li-Jia Li, Kai Li, and Li Fei-Fei. ImageNet: A large-scale hierarchical image database. In 2009 IEEE Conference on Computer Vision and Pattern Recognition, pages 248–255, June 2009.
A.1 Training Data
Electrophysiological data were acquired as broadband signal (0.5Hz-16kHz), from a pair of male rhesus macaque monkeys (Macaca mulatta), using 32 channel linear silicon probes (NeuroNexus V1x32-Edge-10mm-60-177). The data was spike-sorted, and single units were isolated based on unit stability, refractory periods, and channel principal component pairs. Visual stimuli were presented to the animals on a 16:9 widenscreen HD LCD monitor at  $100\mathrm{cm}$  viewing distance. The animals were rewarded with juice if they maintained their gaze around a red fixation target throughout each trial. At the beginning of each recording session, the receptive fields (RFs) of the neurons were mapped in relation to a fixation target using sparse random dot stimuli, and the population RF was pulled towards the center of the screen by adjusting the fixation target. A collection of 24,075 images from ImageNet [68] was transformed into gray-scale and cropped to the central  $420^2$  px and had 8 bit intensity resolution. These images were presented as visual stimuli during standalone generation recordings of 1244 units and during closed-loop recordings of 82 units. For details on the closed loop paradigm, please refer to Willeke et al. [24].
A.2 Supplementary Experiments
A.2.1 Attention Model
Attention readout uses its ability to shift receptive fields Receptive fields of neurons in area V4 can shift before the onset of saccades, believed to be associated with attentional shifts [26]. We investigate whether the Attention model actually uses its ability to shift the receptive field depending on image content. We inspect the attention mask of the attention model. We compute the center of mass of the upper  $5\%$  percentile of each attention mask. We then compute the average distance between the center of masses across different images for each neuron. We plot the average distance against the test correlation of each neuron observing that the attention readout does perform shifts (Fig. S1a). We also show qualitative examples of the masks and the means in Fig. S1b.
Centered Kernel Alignment We computed CKA of the neural encodings across architectures between the Attention model and Gaussian model and within architecture between different seeds (e.g. Attention 1 and Attention 2 are models with the same architecture, but trained with different seeds). The CKA is computed between the predicted neuronal responses. We observe that the within-architecture similarity is very high ( $>0.99$ ) for both architectures and the cross architecture similarity is slightly lower, but also high ( $>0.9$ ) (Table 2). We expect such an outcome, since both architectures were trained to model the same neural representation.
Model	Attention 1	Attention 2	Gaussian 1	Gaussian 2
Attention 1	1	0.9949	0.9133	0.9116
Attention 2	0.9949	1	0.9145	0.9129
Gaussian 1	0.9133	0.9145	1	0.9994
Gaussian 2	0.9116	0.9129	0.9994	1
Supplementary Table S1: Centered Kernel Alignment for the two architectures comparing across and within architectures.
A.2.2 MEI generation