-1
$\begingroup$

I have 2 tensors a and blike [?,200,200,48] and i want to get the dot product on axis 4 to obtain a tensor like [?,200,200,1].

I tried to use tf.tensordot(a,b,axis=[[3][3]]) and the result is tensor like [?,200,200,?,200,200]

Where i'm bad?

$\endgroup$
0
$\begingroup$

Try this:

from tensorflow.keras.layers import *
import tensorflow.keras.backend as K
import tensorflow as tf

BS = 100
x = K.random_normal((BS, 200, 200, 48))
y = K.random_normal((BS, 200, 200, 48))

K.sum(tf.multiply(x, y[:tf.newaxis]), axis=-1, keepdims=True).shape

Detailed explanation from here: https://stackoverflow.com/questions/51657476/keras-dot-dot-layer-behavior-on-3d-tensors

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you, it works perfectly! $\endgroup$ – bob87 Jul 15 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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