title: TensorFlow: Using None-Values in a Tensor
body: <p>I am trying to use this DSNT-layer from  GitHub:
  <a href="https://github.com/ashwhall/dsnt/" rel="nofollow noreferrer">https://github.com/ashwhall/dsnt/</a></p>
  <p>It seems that the implementation has a problem with the placeholder consisting of the input size and the batch size.
  My understanding is that the batch size is usually unknown during graph initialization unless one defines a batch value in the input layer or until the learning process begins.</p>
  <p>Based on the batch-size, the dsnt layer creates tensors as seen below:</p>
  <pre><code>    batch_count = tf.shape(norm_heatmap)[0]
      height = tf.shape(norm_heatmap)[1]
      width = tf.shape(norm_heatmap)[2]
  
      # TODO scalars for the new coord system
      scalar_x = ((2 * width) - (width + 1)) / width
      scalar_x = tf.cast(scalar_x, tf.float32)
      scalar_y = ((2 * height) - (height + 1)) / height
      scalar_y = tf.cast(scalar_y, tf.float32)
  
      # Build the DSNT x, y matrices
      dsnt_x = tf.tile([[(2 * tf.range(1, width+1) - (width + 1)) / width]], [batch_count, height, 1]) # &lt;-- point of error
      dsnt_x = tf.cast(dsnt_x, tf.float32)
      dsnt_y = tf.tile([[(2 * tf.range(1, height+1) - (height + 1)) / height]], [batch_count, width, 1])
      dsnt_y = tf.cast(tf.transpose(dsnt_y, perm=[0, 2, 1]), tf.float32)
  </code></pre>
  <p>When I run this code, I get following error message:</p>
  <pre><code>raise e.with_traceback(filtered_tb) from None
  ValueError: Shape [1,2,3,4,5,...,64] is too large (more than 2**63 - 1 entries) for '{{node Placeholder}} = Placeholder[dtype=DT_INT32, shape=[1,2,3,4,5,..., 64]]()' with input shapes: .
  
  </code></pre>
  <p>I found answers in stackoverflow recommending to use tf.shape to avoid problems with handling unknown dimensions. This does not seem to be enough here.</p>
  <p>If an input with dimension (none, none, 1) is used, the code is executed. Furthermore, it will be executed when running on Tensorflow 2.5.3 or lower.</p>
  <p><strong>My Question</strong>:
  How do I use unknown values that will be defined only when the process of learning started.</p>
  <p>I attached a minimal example:
  Using Python3.10 and Tensorflow2.8</p>
  <p>The input is an image of a certain size, e.g. 128x64x1, and the output is the normalized coordinate of the center of mass.</p>
  <pre><code>def Minimal_Model(_):
      input_shape = (128, 64, 1)
      X_input = Input(shape=input_shape)
      X_out = Conv2D(filters=1, kernel_size=(1, 1), strides=(1, 1), padding='valid',
                     name=&quot;conv&quot;, kernel_initializer=he_uniform())(X_input)
  
      norm_heatmap, coordinates = dsnt.dsnt(X_out)
      model = Model(inputs=X_input, outputs=coordinates, name='Test-DSNT')
  
      model.compile(optimizer=tensorflow.keras.optimizers.Adam(0.0001),
                    loss=[tf.keras.losses.MeanSquaredError(), tf.keras.losses.MeanSquaredError()],
                    metrics=[tf.keras.metrics.MeanSquaredError()])
      return model
  
  </code></pre>
  <pre><code>import tensorflow as tf
  from models import Minimal_Model
  from keras_tuner.tuners import BayesianOptimization
  import time
  
  tf.get_logger().setLevel('DEBUG')
  
  MAX_TRIALS = 10
  EXECUTION_PER_TRIAL = 1
  BATCH_SIZE = 8
  EPOCHS = 10
  LOG_DIR = 'results-random' + f&quot;{int(time.time())}&quot;
  
  train_images = tf.random.uniform((2000, 64, 128, 1), minval=0, dtype=tf.float32, maxval=1)
  test_images = tf.random.uniform((200, 64, 128, 1), minval=0, dtype=tf.float32, maxval=1)
  train_labels = tf.random.uniform((2000, 2, 1), minval=0, dtype=tf.float32, maxval=1)
  test_labels = tf.random.uniform((200, 2, 1), minval=0, dtype=tf.float32, maxval=1)
  
  tuner = BayesianOptimization(
      Minimal_Model,
      seed=1,
      objective='val_mean_squared_error',
      max_trials=MAX_TRIALS,
      executions_per_trial=EXECUTION_PER_TRIAL,
      directory=LOG_DIR,
      project_name=&quot;project&quot;
  )
  
  tuner.search(train_images, train_labels, epochs=EPOCHS, batch_size=BATCH_SIZE,
               validation_data=(test_images, test_labels),
               callbacks=[tf.keras.callbacks.EarlyStopping(monitor='val_mean_squared_error', restore_best_weights=True,
                                                           patience=3, mode='min')])
  
  # Show a summary of the search
  tuner.results_summary(num_trials=1)
  </code></pre>