user3102085
user3102085

Reputation: 499

AtributeError:int object has no attribute name

Following is my code:

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

Here I am applying thresholding on result. If its value is greater than 0.2 then assign 1 otherwise assign 0. But I keep getting this error. Kindly tell what I am doing wrong.

Traceback:

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'

Upvotes: 1

Views: 2737

Answers (1)

DomJack
DomJack

Reputation: 4183

The callbacks should return tensors, not ints. Try:

one = tf.constant(1, dtype=tf.int32, name='one')
zero = tf.constant(0, dtype=tf.int32, name='zero')

and inside the class:

def truef(self):
    return one

def falsef(self):
    return zero

Upvotes: 1

Related Questions