Tensorflow: Using tf.slice to split the input

后端 未结 3 1300
梦毁少年i
梦毁少年i 2021-02-20 03:22

I\'m trying to split my input layer into different sized parts. I\'m trying to use tf.slice to do that but it\'s not working.

Some sample code:

import te         


        
3条回答
  •  不要未来只要你来
    2021-02-20 04:13

    You can specify one negative dimension in the size parameter of tf.slice. The negative dimension tells Tensorflow to dynamically determine the right value basing its decision on the other dimensions.

    import tensorflow as tf
    import numpy as np
    
    ph = tf.placeholder(shape=[None,3], dtype=tf.int32)
    
    # look the -1 in the first position
    x = tf.slice(ph, [0, 0], [-1, 2])
    
    input_ = np.array([[1,2,3],
                       [3,4,5],
                       [5,6,7]])
    
    with tf.Session() as sess:
            sess.run(tf.initialize_all_variables())
            print(sess.run(x, feed_dict={ph: input_}))
    

提交回复
热议问题