How to convert numpy arrays to standard TensorFlow format?

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

    You can use placeholders and feed_dict.

    Suppose we have numpy arrays like these:

    trX = np.linspace(-1, 1, 101) 
    trY = 2 * trX + np.random.randn(*trX.shape) * 0.33 
    

    You can declare two placeholders:

    X = tf.placeholder("float") 
    Y = tf.placeholder("float")
    

    Then, use these placeholders (X, and Y) in your model, cost, etc.: model = tf.mul(X, w) ... Y ... ...

    Finally, when you run the model/cost, feed the numpy arrays using feed_dict:

    with tf.Session() as sess:
    .... 
        sess.run(model, feed_dict={X: trY, Y: trY})
    

提交回复
热议问题