以下是我的代码:
def cos_dist(self,net_1,net_2,sess):
#result
result=tf.div(product_norm,denom)
r=tf.cond(result>0.2,self.truef,self.falsef)
return r
def truef(self):
return 1
def falsef(self):
return 0
这里我对结果应用阈值处理。如果它的值大于0.2,则分配1,否则分配0.但是我不断收到此错误。请告诉我我做错了什么。
回溯:
Traceback (most recent call last):
File "f.py", line 326, in <module>
vgg = vgg16(imgs1,imgs2, 'vgg16_weights.npz', sess)
File "f.py", line 39, in __init__
self.cd=self.cos_dist(self.o1,self.o2,sess)
File "f.py", line 312, in cos_dist
r=tf.cond(result>0.2,self.truef,self.falsef)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 1776, in cond
orig_res, res_t = context_t.BuildCondBranch(fn1)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 1703, in BuildCondBranch
real_v = self._ProcessOutputTensor(v)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 1661, in _ProcessOutputTensor
if val.name not in self._values:
AttributeError: 'int' object has no attribute 'name'
答案 0 :(得分:1)
回调应该返回张量,而不是整数。尝试:
one = tf.constant(1, dtype=tf.int32, name='one')
zero = tf.constant(0, dtype=tf.int32, name='zero')
并在课堂内:
def truef(self):
return one
def falsef(self):
return zero