Tensorflow:TypeError: pred must not be a Python bool

這個問題常見且不小心就會遇到,記錄下O(∩_∩)O哈!

frr@frr:~/Documents/code/pointnet/models$ python pointnet_SE.py
('input_image', <tf.Tensor 'ExpandDims:0' shape=(32, 1024, 3, 1) dtype=float32>)
Traceback (most recent call last):
  File "pointnet_SE.py", line 138, in <module>
    net, end_points = get_model(inputs, True)
  File "pointnet_SE.py", line 37, in get_model
    transform = input_transform_net(net, is_training, bn_decay, K=3)
  File "/home/frr/Documents/code/pointnet/models/transform_nets.py", line 29, in input_transform_net
    scope='tconv1', bn_decay=bn_decay)
  File "/home/frr/Documents/code/pointnet/models/../utils/tf_util.py", line 167, in conv2d
    bn_decay=bn_decay, scope='bn')
  File "/home/frr/Documents/code/pointnet/models/../utils/tf_util.py", line 536, in batch_norm_for_conv2d
    return batch_norm_template(inputs, is_training, scope, [0, 1, 2], bn_decay)
  File "/home/frr/Documents/code/pointnet/models/../utils/tf_util.py", line 482, in batch_norm_template
    lambda: tf.no_op())
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/deprecation.py", line 289, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 1802, in cond
    raise TypeError("pred must not be a Python bool")
TypeError: pred must not be a Python bool

貼出一段先嚇一下小夥伴們,有些小夥伴可能剛接觸代碼沒有很久,碰到error就會非常煩躁,甚至直接就give up了,但是作爲祖國花朵的我們怎麼能說放棄就放棄呢?其實看着這段報錯很嚇人,有用的只有最後一行!!

TypeError: pred must not be a Python bool

其實就是個類型錯誤,或者不兼容的問題,
LZ直接定義is_training = True,因爲定義的is_training=True不是tf.bool類型,所以導致不兼容,只要定義的時候加上type就行了,舉個例子:

is_training = tf.cast(True, tf.bool)

調代碼就還是得慢慢來,切勿心浮氣躁,小夥伴們加油!哈哈,順便祝下自己生日快樂,Felaim每天要加油,開心O(∩_∩)O~~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章