How to convert numpy arrays to standard TensorFlow format?

前端 未结 3 828
野的像风
野的像风 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:25

    You can use tf.convert_to_tensor():

    import tensorflow as tf
    import numpy as np
    
    data = [[1,2,3],[4,5,6]]
    data_np = np.asarray(data, np.float32)
    
    data_tf = tf.convert_to_tensor(data_np, np.float32)
    
    sess = tf.InteractiveSession()  
    print(data_tf.eval())
    
    sess.close()
    

    Here's a link to the documentation for this method:

    https://www.tensorflow.org/api_docs/python/tf/convert_to_tensor

提交回复
热议问题