How to convert numpy arrays to standard TensorFlow format?

前端 未结 3 820
野的像风
野的像风 2020-12-28 12:42

I have two numpy arrays:

  • One that contains captcha images
  • Another that contains the corresponding labels (in one-hot vector format)

3条回答
  •  遥遥无期
    2020-12-28 13:22

    You can use tf.pack (tf.stack in TensorFlow 1.0.0) method for this purpose. Here is how to pack a random image of type numpy.ndarray into a Tensor:

    import numpy as np
    import tensorflow as tf
    random_image = np.random.randint(0,256, (300,400,3))
    random_image_tensor = tf.pack(random_image)
    tf.InteractiveSession()
    evaluated_tensor = random_image_tensor.eval()
    

    UPDATE: to convert a Python object to a Tensor you can use tf.convert_to_tensor function.

提交回复
热议问题