1. 程式人生 > >tensorflow-檢測浮點數型別check_numerics

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