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'>
posted on 2019-05-29 19:04 happygril3 阅读(5641) 评论(0) 编辑 收藏 举报