tensor与数组转化


import tensorflow as tf
img1 = tf.constant(value=[[[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[4]]]],dtype=tf.float32)
img2 = tf.constant(value=[[[[1],[1],[1],[1]],[[1],[1],[1],[1]],[[1],[1],[1],[1]],[[1],[1],[1],[1]]]],dtype=tf.float32)
img = tf.concat(values=[img1,img2],axis=3)      #<class 'tensorflow.python.framework.ops.Tensor'>
sess=tf.Session()

#sess.run(tf.initialize_all_variables())
sess.run(tf.global_variables_initializer())

#转化为numpy数组
img_numpy=img.eval(session=sess) #<class 'numpy.ndarray'>

#转化为tensor
img_tensor= tf.convert_to_tensor(img_numpy) #<class 'tensorflow.python.framework.ops.Tensor'>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM