title: Tensor Dimensions must be equal
body: <p>I am writing my own code for False alarm metrics in Keras for Neural networks. The Neural network implemented gives an output of (100,1) dimension, where each output value is between 0 and 1. The batch size is 1000. In the false_alarm1 function, I want to select the top k probabilities and make them 1 and the rest equal to 0 and then calculate the confusion matrix. I received a message that the dimensions do not match. I tried all the solutions available on the internet for a similar problem but nothing seems to work.</p>
  <p>Here is the function, I implemented</p>
  <pre><code>def false_alarm1(y_true, y_pred): #based on the Top K probabilities
  
  values , indices =tf.math.top_k(y_pred, k =2)
  topk_value = tf.math.argmin(input = values, axis =-1)
  topk_value = tf.broadcast_to(topk_value , shape = tf.shape(y_pred))
  topk_value = K.cast(topk_value, K.floatx())
  y_pred = K.cast(y_pred, K.floatx())
  y_pred = K.greater_equal(y_pred , topk_value)
  y_pred = K.cast(y_pred, K.floatx())
  y_true = K.cast(y_true, K.floatx())
  a = K.reshape(y_pred, [-1])
  b = K.reshape(y_true, [-1])
  conf = tf.math.confusion_matrix(b, a)/tf.shape(a)[0]
  score1 = conf[0][1]/(conf[0][0] + conf[0][1])
  return score1
  </code></pre>
  <p>I also tried this</p>
  <pre><code>topk_value = tf.broadcast_to(topk_value , shape = (1000,100))
  </code></pre>
  <p>The progress of the NN</p>
  <pre><code>Train on 8000 samples
  
  1000/8000 [==&gt;...........................] - ETA: 5s
  </code></pre>
  <p>The error I received</p>
  <pre><code>InvalidArgumentError: Dimensions must be equal, but are 1000 and 100 for 'metrics/false_alarm1/BroadcastTo' (op: 'BroadcastTo') with input shapes: [1000], [2] and with input tensors computed as partial shapes: input[1] = [1000,100].
  
  ValueError: Dimensions must be equal, but are 1000 and 100 for 'metrics/false_alarm1/BroadcastTo' (op: 'BroadcastTo') with input shapes: [1000], [2] and with input tensors computed as partial shapes: input[1] = [1000,100].
  </code></pre>
  <p>My Model:</p>
  <pre><code>    __________________________________________________________________________________________________
  Layer (type)                    Output Shape         Param #     Connected to                     
  ==================================================================================================
  input_1 (InputLayer)            [(None, 140)]        0                                            
  __________________________________________________________________________________________________
  dense (Dense)                   (None, 1000)         141000      input_1[0][0]                    
  __________________________________________________________________________________________________
  batch_normalization (BatchNorma (None, 1000)         4000        dense[0][0]                      
  __________________________________________________________________________________________________
  dense_1 (Dense)                 (None, 1000)         1001000     batch_normalization[0][0]        
  __________________________________________________________________________________________________
  batch_normalization_1 (BatchNor (None, 1000)         4000        dense_1[0][0]                    
  __________________________________________________________________________________________________
  re_lu (ReLU)                    (None, 1000)         0           batch_normalization_1[0][0]      
  __________________________________________________________________________________________________
  dropout (Dropout)               (None, 1000)         0           re_lu[0][0]                      
  __________________________________________________________________________________________________
  add (Add)                       (None, 1000)         0           dropout[0][0]                    
                                                                   batch_normalization[0][0]        
  __________________________________________________________________________________________________
  dense_2 (Dense)                 (None, 1000)         1001000     add[0][0]                        
  __________________________________________________________________________________________________
  batch_normalization_2 (BatchNor (None, 1000)         4000        dense_2[0][0]                    
  __________________________________________________________________________________________________
  re_lu_1 (ReLU)                  (None, 1000)         0           batch_normalization_2[0][0]      
  __________________________________________________________________________________________________
  dropout_1 (Dropout)             (None, 1000)         0           re_lu_1[0][0]                    
  __________________________________________________________________________________________________
  add_1 (Add)                     (None, 1000)         0           dropout_1[0][0]                  
                                                                   add[0][0]                        
  __________________________________________________________________________________________________
  dense_3 (Dense)                 (None, 1000)         1001000     add_1[0][0]                      
  __________________________________________________________________________________________________
  batch_normalization_3 (BatchNor (None, 1000)         4000        dense_3[0][0]                    
  __________________________________________________________________________________________________
  re_lu_2 (ReLU)                  (None, 1000)         0           batch_normalization_3[0][0]      
  __________________________________________________________________________________________________
  dropout_2 (Dropout)             (None, 1000)         0           re_lu_2[0][0]                    
  __________________________________________________________________________________________________
  add_2 (Add)                     (None, 1000)         0           dropout_2[0][0]                  
                                                                   add_1[0][0]                      
  __________________________________________________________________________________________________
  dense_4 (Dense)                 (None, 1000)         1001000     add_2[0][0]                      
  __________________________________________________________________________________________________
  batch_normalization_4 (BatchNor (None, 1000)         4000        dense_4[0][0]                    
  __________________________________________________________________________________________________
  re_lu_3 (ReLU)                  (None, 1000)         0           batch_normalization_4[0][0]      
  __________________________________________________________________________________________________
  dropout_3 (Dropout)             (None, 1000)         0           re_lu_3[0][0]                    
  __________________________________________________________________________________________________
  add_3 (Add)                     (None, 1000)         0           dropout_3[0][0]                  
                                                                   add_2[0][0]                      
  __________________________________________________________________________________________________
  dense_5 (Dense)                 (None, 1000)         1001000     add_3[0][0]                      
  __________________________________________________________________________________________________
  batch_normalization_5 (BatchNor (None, 1000)         4000        dense_5[0][0]                    
  __________________________________________________________________________________________________
  re_lu_4 (ReLU)                  (None, 1000)         0           batch_normalization_5[0][0]      
  __________________________________________________________________________________________________
  dropout_4 (Dropout)             (None, 1000)         0           re_lu_4[0][0]                    
  __________________________________________________________________________________________________
  add_4 (Add)                     (None, 1000)         0           dropout_4[0][0]                  
                                                                   add_3[0][0]                      
  __________________________________________________________________________________________________
  dense_6 (Dense)                 (None, 1000)         1001000     add_4[0][0]                      
  __________________________________________________________________________________________________
  batch_normalization_6 (BatchNor (None, 1000)         4000        dense_6[0][0]                    
  __________________________________________________________________________________________________
  re_lu_5 (ReLU)                  (None, 1000)         0           batch_normalization_6[0][0]      
  __________________________________________________________________________________________________
  dropout_5 (Dropout)             (None, 1000)         0           re_lu_5[0][0]                    
  __________________________________________________________________________________________________
  add_5 (Add)                     (None, 1000)         0           dropout_5[0][0]                  
                                                                   add_4[0][0]                      
  __________________________________________________________________________________________________
  dense_7 (Dense)                 (None, 100)          100100      add_5[0][0]                      
  __________________________________________________________________________________________________
  tf_op_layer_Sigmoid (TensorFlow (None, 100)          0           dense_7[0][0]                    
  ==================================================================================================
  </code></pre>