title: TypeError: Image data of dtype object cannot be converted to float
body: <p>I am using the code from GAN tutorial on generating MNIST digits in tensorflow.</p>
  
  <p>(Link here: <a href="https://www.tensorflow.org/beta/tutorials/generative/dcgan" rel="nofollow noreferrer">https://www.tensorflow.org/beta/tutorials/generative/dcgan</a>)</p>
  
  <p>I got </p>
  
  <pre><code>Traceback (most recent call last):
    File "GAN_MNIST_tutorial.py", line 66, in &lt;module&gt;
      plt.imshow(np.array(generated_image[0, :, :, 0]), cmap='gray')
    File "C:\venv\lib\site-packages\matplotlib\pyplot.py", line 2677, in imshow
      None else {}), **kwargs)
    File "C:\venv\lib\site-packages\matplotlib\__init__.py", line 1589, in inner
      return func(ax, *map(sanitize_sequence, args), **kwargs)
    File "C:\venv\lib\site-packages\matplotlib\cbook\deprecation.py", line 369, in wrapper
      return func(*args, **kwargs)
    File "C:\venv\lib\site-packages\matplotlib\cbook\deprecation.py", line 369, in wrapper
      return func(*args, **kwargs)
    File "C:\venv\lib\site-packages\matplotlib\axes\_axes.py", line 5660, in imshow
      im.set_data(X)
    File "C:\venv\lib\site-packages\matplotlib\image.py", line 678, in set_data
      "float".format(self._A.dtype))
  TypeError: Image data of dtype object cannot be converted to float
  </code></pre>
  
  <p>when I ran it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>from __future__ import absolute_import, division, print_function, unicode_literals
  
  import tensorflow as tf 
  tf.__version__
  
  import glob
  import imageio
  import matplotlib.pyplot as plt
  import numpy as np
  import os
  import PIL
  from tensorflow.keras import layers
  import time
  
  def make_generator_model():
      model = tf.keras.Sequential()
      model.add(layers.Dense(7*7*256, use_bias=False, input_shape=(100,)))
      model.add(layers.BatchNormalization())
      model.add(layers.LeakyReLU())
      model.add(layers.Reshape((7, 7, 256)))
  
      assert model.output_shape == (None, 7, 7, 256) # Note: None is the batch size
  
      model.add(layers.Conv2DTranspose(128, (5, 5), strides=(1, 1), padding='same', use_bias=False))
      assert model.output_shape == (None, 7, 7, 128)
  
      model.add(layers.BatchNormalization())
      model.add(layers.LeakyReLU())
  
      model.add(layers.Conv2DTranspose(64, (5, 5), strides=(2, 2), padding='same', use_bias=False))
      assert model.output_shape == (None, 14, 14, 64)
  
      model.add(layers.BatchNormalization())
      model.add(layers.LeakyReLU())
  
      model.add(layers.Conv2DTranspose(1, (5, 5), strides=(2, 2), padding='same', use_bias=False, activation='tanh'))
      assert model.output_shape == (None, 28, 28, 1)
  
      return model
  
  generator = make_generator_model()
  
  noise = tf.random.normal([1, 100])
  
  generated_image = generator(noise, training=False)
  
  plt.imshow(generated_image[0, :, :, 0], cmap='gray')
  </code></pre>
  
  <p>I've tried adding <code>dtype = 'float32</code> in <code>generated_image</code>, and converting <code>generated_image</code> into an numpy array, but to no avail. What is the problem?</p>