报错:No registered ‘swish_f32‘ OpKernel for GPU devices compatible with node

日萌社

人工智能AI:Keras PyTorch MXNet TensorFlow PaddlePaddle 深度学习实战(不定时更新)


1.报错:tensorflow/core/grappler/utils/graph_view.cc:830] No registered 'swish_f32' OpKernel for GPU devices compatible with node 
	{{node swish_75/swish_f32}}  Registered:  <no registered kernels> 
2.解决:把 tf.nn.swish(inputs) 替换为 inputs * tf.math.sigmoid(inputs)
3.分析:tf.nn.swish(x) 的底层实际封装了 x * sigmoid(x)

	β是个常数或可训练的参数.Swish 具备无上界有下界、平滑、非单调的特性。
	Swish 在深层模型上的效果优于 ReLU。例如,仅仅使用 Swish 单元替换 ReLU 就能把 Mobile NASNetA 在 ImageNet 上的 top-1 分类准确率提高 0.9%,
	Inception-ResNet-v 的分类准确率提高 0.6%。
	当β = 0时,Swish变为线性函数f(x)=x2f(x)=x2.
	β → ∞, σ(x)=(1+exp(−x))−1σ(x)=(1+exp⁡(−x))−1为0或1. Swish变为ReLU: f(x)=2max(0,x)
	所以Swish函数可以看做是介于线性函数与ReLU函数之间的平滑函数.
	工程实现:在TensorFlow框架中只需一行代码: x * tf.sigmoid(beta * x)或tf.nn.swish(x).
1.window中使用了 tf.compat.v1.disable_eager_execution() 的同时,还使用 tf.nn.swish(x)的话,会报错如下:
	tensorflow/core/grappler/utils/graph_view.cc:830] No registered 'swish_f32' OpKernel for GPU devices compatible with node
   	{{node swish_75/swish_f32}}  Registered:  <no registered kernels>
2.解决:使用x * tf.sigmoid(beta * x)来代替tf.nn.swish(x)
3.分析:tf.nn.swish(x) 等同于把 x * tf.sigmoid(beta * x) 封装了。
  如果使用了tf.nn.swish(x) 则需要同时使用tf.compat.v1.disable_eager_execution()。
  如果使用x * tf.sigmoid(beta * x)来代替tf.nn.swish(x)的话,则可以不使用tf.compat.v1.disable_eager_execution()。

import tensorflow as tf
import numpy as np

x=np.array([[1.,8.,7.],[10.,14.,3.],[1.,2.,4.]])
tf.math.sigmoid(x)
    <tf.Tensor: id=22, shape=(3, 3), dtype=float64, numpy=
    array([[0.73105858, 0.99966465, 0.99908895],
           [0.9999546 , 0.99999917, 0.95257413],
           [0.73105858, 0.88079708, 0.98201379]])>

tf.compat.v1.disable_eager_execution()
x=np.array([[1.,8.,7.],[10.,14.,3.],[1.,2.,4.]])	 
tf.nn.swish(x)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

あずにゃん

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值