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'>

猜你喜欢

转载自www.cnblogs.com/hapyygril/p/10945633.html
今日推荐