title: ValueError: Can't convert Python sequence with out-of-range integer to Tensor
body: <p>I'm trying to make a binary classifier, to check if an image is a letter or not. I've created the required dataset, and made a basic model to start, but I'm getting this error -</p>
  <pre><code>ValueError: Can't convert Python sequence with out-of-range integer to Tensor.
  </code></pre>
  <p>Looked it up, as saw that it could happen if the data was in different dtypes, but eve after converting it all to float64, the error persists.</p>
  <p>Do you have any clue as to why this might be?</p>
  <pre><code>norm_train_x, y_ = emnist.extract_training_samples('letters')
  norm_test_x, y__ = emnist.extract_test_samples('letters')
  
  norm_train_y = np.array([1] * len(norm_train_x))
  norm_test_y = np.array([1] * len(norm_test_x))
  
  norm_train_x = np.reshape(norm_train_x, (norm_train_x.shape[0], 28, 28, 1))
  norm_test_x = np.reshape(norm_test_x, (norm_test_x.shape[0], 28, 28, 1))
  </code></pre>
  <p>My target is to create a classifier to identify whether an image is a letter or not, so I'm creating a dataset with imgs and random lines, denoted with respective labels being 1s and 0s.</p>
  <p>Here's the code to load all the data and prepare for final use. I've stored all the random images in two folders.</p>
  <pre><code>def load_data():
    random_train_x = []
    for x in range(len(norm_train_x)):
      im = cv2.imread(r'/content/random_train_imgs/img_' + str(x) + '.png')
      im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
      im = np.reshape(im, (28, 28, 1))
      random_train_x.append(im)
  
    random_train_x = np.array(random_train_x)
    random_train_y = np.array([0] * len(random_train_x))
  
    print(random_train_x.shape, random_train_y.shape)
  
    random_test_x = []
    for x in range(len(norm_test_x)):
      im = cv2.imread(r'/content/random_test_imgs/img_' + str(x) + '.png')
      im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
      im = np.reshape(im, (28, 28, 1))
      random_test_x.append(im)
  
    random_test_x = np.array(random_test_x)
    random_test_y = np.array([0] * len(random_test_x))
  
    print(random_test_x.shape, random_test_y.shape)
  
    return (random_train_x, random_train_y), (random_test_x, random_test_y)
  
  
  def finalise_data():
    global random_train_x, random_train_y, random_test_x, random_test_y
    global norm_train_X, norm_test_x, norm_train_y, norm_test_y
  
    train_x = np.concatenate((random_train_x, norm_train_x), axis=0)
    test_x = np.concatenate((random_test_x, norm_test_x), axis=0)
    train_y = np.concatenate((random_train_y, norm_train_y), axis=0)
    test_y = np.concatenate((random_test_y, norm_test_y), axis=0)
  
    test_shuffle = np.random.permutation(len(test_y))
    train_shuffle = np.random.permutation(len(train_y))
  
    train_x, train_y = train_x[train_shuffle], train_y[train_shuffle]
    test_x, test_y = test_x[test_shuffle], test_y[test_shuffle]
  
    print(train_x.shape, train_y.shape)
    print(test_x.shape, test_y.shape)
  
    return (train_x, train_y), (test_x, test_y)
  
  train_x = train_x.astype('float32')
  train_y = train_y.astype('float32')
  test_x = test_x.astype('float32')
  test_y = test_y.astype('float32')
  </code></pre>
  <p>The model architecture</p>
  <pre><code>model = models.Sequential([
                             layers.Flatten(input_shape=[28, 28, 1]),
                             layers.Dense(28**28, activation='relu'),
                             layers.Dense(3)
  ])
  model.summary()
  model.compile(optimizer=tf.keras.optimizers.Adam(), 
                loss=tf.keras.losses.SparseCategoricalCrossentropy(),
                metrics=['accuracy'])
  model.fit(train_x, train_y, validation_data=(test_x, test_y), epochs=10)
  </code></pre>
  <p>The complete traceback:</p>
  <pre><code>---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-8-761e0b4a48eb&gt; in &lt;module&gt;()
        2                            layers.Flatten(input_shape=[28, 28, 1]),
        3                            layers.Dense(28**28, activation='relu'),
  ----&gt; 4                            layers.Dense(3)
        5 ])
        6 model.summary()
  
  31 frames
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
      528     self._self_setattr_tracking = False  # pylint: disable=protected-access
      529     try:
  --&gt; 530       result = method(self, *args, **kwargs)
      531     finally:
      532       self._self_setattr_tracking = previous_value  # pylint: disable=protected-access
  
  /usr/local/lib/python3.7/dist-packages/keras/engine/sequential.py in __init__(self, layers, name)
      132         layers = [layers]
      133       for layer in layers:
  --&gt; 134         self.add(layer)
      135 
      136   @property
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
      528     self._self_setattr_tracking = False  # pylint: disable=protected-access
      529     try:
  --&gt; 530       result = method(self, *args, **kwargs)
      531     finally:
      532       self._self_setattr_tracking = previous_value  # pylint: disable=protected-access
  
  /usr/local/lib/python3.7/dist-packages/keras/engine/sequential.py in add(self, layer)
      215       # If the model is being built continuously on top of an input layer:
      216       # refresh its output.
  --&gt; 217       output_tensor = layer(self.outputs[0])
      218       if len(tf.nest.flatten(output_tensor)) != 1:
      219         raise ValueError(SINGLE_LAYER_OUTPUT_ERROR_MSG)
  
  /usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
      975     if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
      976       return self._functional_construction_call(inputs, args, kwargs,
  --&gt; 977                                                 input_list)
      978 
      979     # Maintains info about the `Layer.call` stack.
  
  /usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
     1113       # Check input assumptions set after layer building, e.g. input shape.
     1114       outputs = self._keras_tensor_symbolic_call(
  -&gt; 1115           inputs, input_masks, args, kwargs)
     1116 
     1117       if outputs is None:
  
  /usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in _keras_tensor_symbolic_call(self, inputs, input_masks, args, kwargs)
      846       return tf.nest.map_structure(keras_tensor.KerasTensor, output_signature)
      847     else:
  --&gt; 848       return self._infer_output_signature(inputs, args, kwargs, input_masks)
      849 
      850   def _infer_output_signature(self, inputs, args, kwargs, input_masks):
  
  /usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in _infer_output_signature(self, inputs, args, kwargs, input_masks)
      884           # overridden).
      885           # TODO(kaftan): do we maybe_build here, or have we already done it?
  --&gt; 886           self._maybe_build(inputs)
      887           inputs = self._maybe_cast_inputs(inputs)
      888           outputs = call_fn(inputs, *args, **kwargs)
  
  /usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in _maybe_build(self, inputs)
     2657         # operations.
     2658         with tf_utils.maybe_init_scope(self):
  -&gt; 2659           self.build(input_shapes)  # pylint:disable=not-callable
     2660       # We must set also ensure that the layer is marked as built, and the build
     2661       # shape is stored since user defined build functions may not be calling
  
  /usr/local/lib/python3.7/dist-packages/keras/layers/core.py in build(self, input_shape)
     1183         constraint=self.kernel_constraint,
     1184         dtype=self.dtype,
  -&gt; 1185         trainable=True)
     1186     if self.use_bias:
     1187       self.bias = self.add_weight(
  
  /usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in add_weight(self, name, shape, dtype, initializer, regularizer, trainable, constraint, use_resource, synchronization, aggregation, **kwargs)
      661         synchronization=synchronization,
      662         aggregation=aggregation,
  --&gt; 663         caching_device=caching_device)
      664     if regularizer is not None:
      665       # TODO(fchollet): in the future, this should be handled at the
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/training/tracking/base.py in _add_variable_with_custom_getter(self, name, shape, dtype, initializer, getter, overwrite, **kwargs_for_getter)
      816         dtype=dtype,
      817         initializer=initializer,
  --&gt; 818         **kwargs_for_getter)
      819 
      820     # If we set an initializer and the variable processed it, tracking will not
  
  /usr/local/lib/python3.7/dist-packages/keras/engine/base_layer_utils.py in make_variable(name, shape, dtype, initializer, trainable, caching_device, validate_shape, constraint, use_resource, collections, synchronization, aggregation, partitioner)
      127       synchronization=synchronization,
      128       aggregation=aggregation,
  --&gt; 129       shape=variable_shape if variable_shape else None)
      130 
      131 
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/variables.py in __call__(cls, *args, **kwargs)
      264   def __call__(cls, *args, **kwargs):
      265     if cls is VariableV1:
  --&gt; 266       return cls._variable_v1_call(*args, **kwargs)
      267     elif cls is Variable:
      268       return cls._variable_v2_call(*args, **kwargs)
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/variables.py in _variable_v1_call(cls, initial_value, trainable, collections, validate_shape, caching_device, name, variable_def, dtype, expected_shape, import_scope, constraint, use_resource, synchronization, aggregation, shape)
      225         synchronization=synchronization,
      226         aggregation=aggregation,
  --&gt; 227         shape=shape)
      228 
      229   def _variable_v2_call(cls,
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/variables.py in &lt;lambda&gt;(**kwargs)
      203                         shape=None):
      204     &quot;&quot;&quot;Call on Variable class. Useful to force the signature.&quot;&quot;&quot;
  --&gt; 205     previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs)
      206     for _, getter in ops.get_default_graph()._variable_creator_stack:  # pylint: disable=protected-access
      207       previous_getter = _make_getter(getter, previous_getter)
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/variable_scope.py in default_variable_creator(next_creator, **kwargs)
     2624         synchronization=synchronization,
     2625         aggregation=aggregation,
  -&gt; 2626         shape=shape)
     2627   else:
     2628     return variables.RefVariable(
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/variables.py in __call__(cls, *args, **kwargs)
      268       return cls._variable_v2_call(*args, **kwargs)
      269     else:
  --&gt; 270       return super(VariableMetaclass, cls).__call__(*args, **kwargs)
      271 
      272 
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/resource_variable_ops.py in __init__(self, initial_value, trainable, collections, validate_shape, caching_device, name, dtype, variable_def, import_scope, constraint, distribute_strategy, synchronization, aggregation, shape)
     1611           aggregation=aggregation,
     1612           shape=shape,
  -&gt; 1613           distribute_strategy=distribute_strategy)
     1614 
     1615   def _init_from_args(self,
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/resource_variable_ops.py in _init_from_args(self, initial_value, trainable, collections, caching_device, name, dtype, constraint, synchronization, aggregation, distribute_strategy, shape)
     1738           with ops.name_scope(&quot;Initializer&quot;), device_context_manager(None):
     1739             if init_from_fn:
  -&gt; 1740               initial_value = initial_value()
     1741             if isinstance(initial_value, trackable.CheckpointInitialValue):
     1742               self._maybe_initialize_trackable()
  
  /usr/local/lib/python3.7/dist-packages/keras/initializers/initializers_v2.py in __call__(self, shape, dtype, **kwargs)
      515     else:
      516       limit = math.sqrt(3.0 * scale)
  --&gt; 517       return self._random_generator.random_uniform(shape, -limit, limit, dtype)
      518 
      519   def get_config(self):
  
  /usr/local/lib/python3.7/dist-packages/keras/initializers/initializers_v2.py in random_uniform(self, shape, minval, maxval, dtype)
      971       op = tf.random.uniform
      972     return op(
  --&gt; 973         shape=shape, minval=minval, maxval=maxval, dtype=dtype, seed=self.seed)
      974 
      975   def truncated_normal(self, shape, mean, stddev, dtype):
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
      204     &quot;&quot;&quot;Call target, and fall back on dispatchers if there is a TypeError.&quot;&quot;&quot;
      205     try:
  --&gt; 206       return target(*args, **kwargs)
      207     except (TypeError, ValueError):
      208       # Note: convert_to_eager_tensor currently raises a ValueError, not a
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/random_ops.py in random_uniform(shape, minval, maxval, dtype, seed, name)
      294     maxval = 1
      295   with ops.name_scope(name, &quot;random_uniform&quot;, [shape, minval, maxval]) as name:
  --&gt; 296     shape = tensor_util.shape_tensor(shape)
      297     # In case of [0,1) floating results, minval and maxval is unused. We do an
      298     # `is` comparison here since this is cheaper than isinstance or  __eq__.
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/tensor_util.py in shape_tensor(shape)
     1078       # not convertible to Tensors because of mixed content.
     1079       shape = tuple(map(tensor_shape.dimension_value, shape))
  -&gt; 1080   return ops.convert_to_tensor(shape, dtype=dtype, name=&quot;shape&quot;)
     1081 
     1082 
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/profiler/trace.py in wrapped(*args, **kwargs)
      161         with Trace(trace_name, **trace_kwargs):
      162           return func(*args, **kwargs)
  --&gt; 163       return func(*args, **kwargs)
      164 
      165     return wrapped
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py in convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, dtype_hint, ctx, accepted_result_types)
     1564 
     1565     if ret is None:
  -&gt; 1566       ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
     1567 
     1568     if ret is NotImplemented:
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref)
      344                                          as_ref=False):
      345   _ = as_ref
  --&gt; 346   return constant(v, dtype=dtype, name=name)
      347 
      348 
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name)
      270   &quot;&quot;&quot;
      271   return _constant_impl(value, dtype, shape, name, verify_shape=False,
  --&gt; 272                         allow_broadcast=True)
      273 
      274 
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/constant_op.py in _constant_impl(value, dtype, shape, name, verify_shape, allow_broadcast)
      281       with trace.Trace(&quot;tf.constant&quot;):
      282         return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
  --&gt; 283     return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
      284 
      285   g = ops.get_default_graph()
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/constant_op.py in _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
      306 def _constant_eager_impl(ctx, value, dtype, shape, verify_shape):
      307   &quot;&quot;&quot;Creates a constant on the current device.&quot;&quot;&quot;
  --&gt; 308   t = convert_to_eager_tensor(value, ctx, dtype)
      309   if shape is None:
      310     return t
  
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
      104       dtype = dtypes.as_dtype(dtype).as_datatype_enum
      105   ctx.ensure_initialized()
  --&gt; 106   return ops.EagerTensor(value, ctx.device_name, dtype)
      107 
      108 
  
  ValueError: Can't convert Python sequence with out-of-range integer to Tensor.
  </code></pre>