tensorflow-检测浮点数类型check_numerics

参数 'tensor' 要属于以下类型才能通过 bfloat16, float16, float32, float64,返回原tensorflow。否则报InvalidArgument 错误。

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 27 11:16:32 2018

@author: myhaspl
"""

import tensorflow as tf
a = tf.constant([[1., 2.], [3., 4.]])
b = tf.constant([[1, 2], [3, 4]])

check_a=tf.check_numerics(a,"non number")
#check_b=tf.check_numerics(b,"non number")                                                            
sess=tf.Session()
with sess:
    print sess.run(check_a)
   # print sess.run(check_b)

[[1. 2.]
 [3. 4.]]

去除注释,将报错

TypeError: Value passed to parameter 'tensor' has DataType int32 not in list of allowed values: bfloat16, float16, float32, float64

猜你喜欢

转载自blog.51cto.com/13959448/2332320