I have a tensor of shape (1, M) where M is a multiple of 10. When I print the tensor it may look something like

Tensor("some_name", shape = (1, 80), dtype = float32)

This tensor is the output of a neural network which will be run in a session. I wanted to modify this tensor according to the following (broken)code:

for chunk_number in range(int(tensor.shape[1]/10)):
    this_chunk = my_fn(tensor[10*chunk_number : 10*(chunk_number+1)]) // my_fn is custom
    tf.assign(tensor[10*chunk_number : 10*(chunk_number+1)], this_chunk)

This is essentially like a custom activation function that selectively modifies the output.

However I cannot use a separate tf.Session() to run the tf.assign function because there will be a session running for the neural network. How do I go about this assignment?

  • $\begingroup$ What kind of error do you get if you try to run this code? $\endgroup$
    – Jens K
    Nov 26, 2019 at 8:18

1 Answer 1


Try updating to Tensorflow 2.0. With it you can fiddle with your network, when it's running.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.