tensorflow / lucid

A collection of infrastructure and tools for research in neural network interpretability.
Apache License 2.0
4.65k stars 655 forks source link

Add memory efficient model.get_activations() #224

Closed colah closed 4 years ago

colah commented 4 years ago

The goal of this PR is to add a model.get_activations() function which can get activations for large n-dimensional families of lazily generated images. In the course of accomplishing this, I had to do a few other things:

(1) Add a number of utilities for using iterable workflows in n-dimensions. See lucid.misc.iter_nd_utils.

(2) Fix an annoying cludge with model.import_graph(). Lucid's convention for accessing the internals of an imported model is to use the T() accessor (inspired by $ in jquery). But for weird historical reasons, only render.import_model returned T, not model.import_graph. To avoid needing to depend on render, I added this support to import_graph (where it really always should have been).

(3) Finally, add a lazy iteration based get_activations and get_activations_iter (more flexible, but not exposed by default). get_activations() is added as a method to model to make it easily accessible.

colah commented 4 years ago

I think either @ludwigschubert or @michaelpetrov would be a good reviewer for this.

CC Nick Barry (uncertain of github handle but will share) since he was running into memory issues with a more naive implementation.