代码复现中遇到的问题

Q:TypeError: Expected int32, got list containing Tensors of type '_Message' instead.
A:
tensorflow tf.concat的版本问题
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3])
should be changed to
net = tf.concat([branch_0, branch_1, branch_2, branch_3], 3)
将坐标的位置从前换到后
新建一个与给定的tensor类型大小一致的tensor,其所有元素为1和0
tf.ones_like(tensor,dype=None,name=None)
tf.zeros_like(tensor,dype=None,name=None)
python 中None算是False
continue and break只在for循环里用

出处:https://blog.csdn.net/william_hehe/article/details/81612640

1.函数功能:

插入一个张量的占位符,这个张量总是被喂入图片数据。相当于一个形参。

形参:只有在被调用时才分配内存单元,在调用结束时,就会释放出所分配的内存单元。

2.函数参数:

dtype:数据类型;shape:数据维度;name:数据名称

3.代码实现:

import tensorflow as tf
input1 = tf.placeholder(tf.float32,[1,2],name="a")
input2 = tf.placeholder(tf.float32,[2,1],name="b")
output1 = tf.multiply(input1,input2) #两个矩阵中对应元素各自相乘
output2 = tf.matmul(input1,input2) #将矩阵a乘以矩阵b,生成a * b。
with tf.Session() as sess:
    print(sess.run(output1,feed_dict={input1:[[1.,2.]],input2:[[3.],[4.]]}))
    print(sess.run(output2, feed_dict={input1: [[1., 2.]], input2: [[3.], [4.]]}))

``

将shape为None的tensor和正常tensor concat

The most general solution is to use the tf.shape() op to get the run-time size of the placeholder, and the tf.tile() op to expand h to the appropriate size:

ph_input = tf.placeholder(dtype=tf.int32, shape=[None, 1])
h = tf.zeros([1, 2], dtype=tf.int32) # …or some other tensor of shape [1, 2]

Get the number of rows in the fed value at run-time.

ph_num_rows = tf.shape(ph_input)[0]

Makes a ph_num_rows x 2 matrix, by tiling h along the row dimension.

h_tiled = tf.tile(h, tf.pack([ph_num_rows, 1]))

result = tf.concat(1, [ph_input, h_tiled])

引用:https://wiki.jikexueyuan.com/project/tensorflow-zh/how_tos/threading_and_queues.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值