日萌社
人工智能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)