codecamp

TensorFlow检查NaN和Inf值的张量

tf.check_numerics

check_numerics ( 
    tensor, 
    message, 
    name = None
 )

请参阅指南:控制流程>调试操作

检查 NaN 和 Inf 值的张量.

当运行时,如果张量有任何不是数字(NaN) 或无穷大(Inf) 的值,就会报告一个 InvalidArgument 错误.否则,按原样通过张量.

ARGS:

  • tensor:一个张量.必须是下列类型之一:half,float32,float64.
  • message:一个字符串.是错误消息的前缀.
  • name:操作的名称(可选).

返回:

返回一个张量,与 tensor 具有相同的类型.


参数 '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.]]


使用ceil返回不下于x的最小整数
TensorFlow计算方阵的Cholesky分解
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }