1

I was building a neural network in tensorflow keras and ended up with the following code as a step in the model:

enc = tfkl.Reshape((-1, 20,input_shape[1]))(input_layer)
encoder_output = []
for i in range(enc.shape[1]):
     o = encoder(enc[:, i, ...])
     encoder_output.append(o)
encoder_output = tf.stack(encoder_output, axis=1)

The code WORKS FINE. However it is quite long in the summary and in general not very elegant. I don't know much about functional API and custom layers. But I would like to know if in this case it's best to use a custom layer or build a functional API block.

Thank you

James__pxlwk
  • 71
  • 1
  • 7
  • Were you able to find the answer? I'm in a similar situation, and like to compute certain steps on my input features, at certain intermediate layers. Calling a function is same, inelegant, and also for some reason, the summary is weird. Every tf operation (concat, pad, subtract, etc.) is being rendered as a separate layer. – varungupta Aug 09 '22 at 09:06
  • Please have a look at these links for detailed understanding on how the [Functional API](https://www.tensorflow.org/guide/keras/functional) and [Custom layers](https://www.tensorflow.org/guide/keras/train_and_evaluate) works. Thank you. –  Jan 20 '23 at 15:17

0 Answers0