Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: re-add activation histograms #118

Open
bersbersbers opened this issue Jan 28, 2022 · 18 comments
Open

Feature request: re-add activation histograms #118

bersbersbers opened this issue Jan 28, 2022 · 18 comments

Comments

@bersbersbers
Copy link

System information.

TensorFlow version: 2.8.0-rc1

Describe the feature and the current behavior/state.

https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/TensorBoard says:

histogram_freq: frequency (in epochs) at which to compute activation and weight histograms for the layers of the model. If set to 0, histograms won't be computed. Validation data (or split) must be specified for histogram visualizations.

But I am fairly certain activation histograms are not written, see also tensorflow/tensorflow#39755 and tensorflow/tensorflow#42027.

Solutions:

  1. re-implement the documented feature (it existed before)
  2. un-document the un-implemented feature

Will this change the current api? How?

1 will not change the API; 2 will change the docs.

Who will benefit from this feature?

Everyone

@Cheril311
Copy link
Contributor

I can try to solve this

@Cheril311
Copy link
Contributor

Hey @bersbersbers as far as I know you can visualize histograms in
tensorboard by using tf.summary.histogram
Can you please attach your code so that I can see if we are on the same page?

@bersbersbers
Copy link
Author

@Cheril311 please see tensorflow/tensorflow#42027 (comment). Keras writes weight histograms, but no activation histograms.

Cheril311 referenced this issue in Cheril311/keras Jan 29, 2022
Addresses issue #15972
@Cheril311
Copy link
Contributor

You seem to be right @bersbersbers , for now I have changed the documentation as I do know how to compute activation histograms but I am unaware on how to write them as tensorboard images

@bersbersbers
Copy link
Author

I do know how to compute activation histograms but I am unaware on how to write them as tensorboard images

I would think activation histograms can be written the same way as the weight histograms, at least in a first iteration. After all, both should have the exact same dimensions.

@Cheril311
Copy link
Contributor

I do know how to compute activation histograms but I am unaware on how to write them as tensorboard images

I would think activation histograms can be written the same way as the weight histograms, at least in a first iteration. After all, both should have the exact same dimensions.

Yup I agree with that but there is some other process done in the function _log_weight_as_image in callbacks.py and I am not sure how to do the same for activations, if you can help me maybe we can submit a pr

@bersbersbers
Copy link
Author

bersbersbers commented Jan 29, 2022

I would think activation histograms can be written the same way as the weight histograms, at least in a first iteration. After all, both should have the exact same dimensions.

Yup I agree with that but there is some other process done in the function _log_weight_as_image in callbacks.py and I am not sure how to do the same for activations, if you can help me maybe we can submit a pr

To my understanding, activations (for one sample) and weights have the same shape, so you can do exactly the same thing as here:

https://github.com/keras-team/keras/blob/8015f697d0109ccd6021fe1b8f2bf5b133b259b9/keras/callbacks.py#L2570-L2580

Since you mentioned in #118 that you know how to compute activation histograms (although I have yet to find a good solution myself, compare https://stackoverflow.com/q/60816678, https://gist.github.com/SiLiKhon/3965c967c3283feccc79822e6252b34c, https://stackoverflow.com/q/66779524), this should be straightforward then. Good luck!

@haifeng-jin
Copy link
Contributor

Summary: The tensorboard callback doesn't print activation histograms. The solution is either change the docs or fix this bug.

@haifeng-jin
Copy link
Contributor

This should have been fixed. Please reopen if it is not.

@bersbersbers
Copy link
Author

@haifeng-jin may I ask where I can see the change? Did you update the docs or implement the functionality?

I don't see any commit on https://github.com/keras-team/keras/commits/master, and https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/TensorBoard (which has been updated for TB2.8.0) still mentions "Activation histograms".

@haifeng-jin
Copy link
Contributor

@bersbersbers Do you reproduce it in TF-nightly? The commit should be sometime ago. This was from the team member who handled this.
If so, you can create a Colab notebook, which can show tensorboard in it.
Thanks

@bersbersbers
Copy link
Author

bersbersbers commented Feb 7, 2022

@haifeng-jin I am getting errors with TensorBoard on tf-nightly (ValueError: Duplicate plugins for name projector), so I cannot test it there. The code that reproduces the issue on TF/TB2.8.0 with keras-nightly (I guess this is the important nightly part) is this:

# pip install tensorflow
# pip uninstall keras
# pip install keras-nightly
import tensorflow as tf
layer = tf.keras.layers.Input(shape=())
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(4, input_shape=(4,)))
model.compile(optimizer="adam", loss="mse")
model.summary()
cb = tf.keras.callbacks.TensorBoard("logs", histogram_freq=1)
model.fit(x=[[1,2,3,4]], y=[[1,2,3,4]], epochs=2, callbacks=[cb])
# tensorboard --logdir logs

And then there's weight histograms, but not activation histograms, just like 1.5 years ago.
image

@bersbersbers
Copy link
Author

(By the way, I'd like to reopen, but cannot.)

image

@LukeWood
Copy link
Contributor

This is now a feature request and contributions are welcome

@bersbersbers
Copy link
Author

bersbersbers commented Feb 12, 2022

Thanks. For the record, I had previously missed the fix to the documentation in 2ba6dea / tensorflow/tensorflow#54196, hence my confusion.

@kydonian
Copy link

Suggest renaming this issue to "Feature request: re-add activation histograms"

@bersbersbers bersbersbers changed the title Feature/documentation request: re-add activation histograms or remove from docs Feature request: re-add activation histograms Mar 24, 2022
@Shreyz-max
Copy link

Shreyz-max commented Aug 27, 2022

@LukeWood anyone working on it? I would like to if no one else is.

@LukeWood
Copy link
Contributor

@LukeWood anyone working on it? I would like to if no one else is.

Dont think so!

@sachinprasadhs sachinprasadhs transferred this issue from keras-team/keras Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants