tensorflow(バージョン1.4)での作業中に、コードのデバッグ中に問題が発生しました。Tensorflowには重大な精度エラーフォールトがあります。ここに例を示しました。テンソルフローでこのタイプの問題を処理する方法はありますか?
>>> a = [18.00146484]
>>> b= [[18.00146484]]
>>> c = [[[18.00146484]]]
>>> d = [[18.00146484],[12.83231735]]
>>> e = [[[18.00146484],[12.83231735]]]
>>> q = tf.nn.sigmoid()
KeyboardInterrupt
>>> q = tf.nn.sigmoid(a)
>>> w = tf.nn.sigmoid(b)
>>> e = tf.nn.sigmoid(c)
>>> r = tf.nn.sigmoid(d)
>>> z = [[[18.00146484],[12.83231735]]]
>>> t = tf.nn.sigmoid(z)
>>> init = tf.global_variables_initializer()
>>> sess = tf.Session()
2017-12-12 15:41:53.766287: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX
>>> qq,ww,ee,rr,tt = sess.run([q,w,e,r,t])
>>> qq,ww,ee,rr,tt
(array([ 1.], dtype=float32), array([[ 1.]], dtype=float32), array([[[ 1.]]], dtype=float32), array([[ 1. ],
[ 0.99999738]], dtype=float32), array([[[ 1. ],
[ 0.99999738]]], dtype=float32))
>>> qq
array([ 1.], dtype=float32)
>>> ww
array([[ 1.]], dtype=float32)
>>> ee
array([[[ 1.]]], dtype=float32)
>>> rrr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'rrr' is not defined
>>> rr
array([[ 1. ],
[ 0.99999738]], dtype=float32)
>>> tt
array([[[ 1. ],
[ 0.99999738]]], dtype=float32)
>>> from math import exp
>>> a = 18.00146484
>>> b = (1/(1+exp(-a)))
>>> b
0.9999999847923136
>>>
まず、試行回数を見ると、テンソルフローが同じ初期値に対して異なる結果をもたらすと感じたかもしれません。そうではないようです。sigmoid(18.00146484)
は常に1で、sigmoid(12.83231735)
常に0.99999938です。
sigmoid(18.00146484)
1から十分に離れているため、1に丸めるべきではないと感じるかもしれませんが、そうではありません。sigmoid(18.00146484) = 0.99999998479231364...
(https://www.wolframalpha.com/input/?i=sigmoid(18.00146484))そしてこの数値はfloat32の精度には1に近すぎます。tf.float64
このレベルの精度を得るには、実際には(テンソルフローで)doubleを使用する必要があります。これは、floatとdoubleの1に最も近い表現可能な数値を表示する単純なC ++プログラムです。
#include <limits>
#include <cmath>
#include <iostream>
int main() {
typedef std::numeric_limits< double > dbl;
typedef std::numeric_limits< double > flt;
double sigmoid = 0.99999998479231364;
float x = 1.0;
double firstSmallerThanX = std::nextafter(x, 0.0f);
std::cout.precision(flt::max_digits10);
std::cout << std::fixed << firstSmallerThanX << std::endl;
std::cout << "Sigmoid is bigger than firstSmallerThanX: " << (sigmoid > firstSmallerThanX) << std::endl;
double y = 1.0;
double firstSmallerThanY = std::nextafter(y, 0.0);
std::cout.precision(dbl::max_digits10);
std::cout << std::fixed << firstSmallerThanY << std::endl;
std::cout << "Sigmoid is smaller than firstSmallerThanY: " << (sigmoid < firstSmallerThanY) << std::endl;
return 0;
}
この印刷物:
0.99999994039535522
Sigmoid is bigger than firstSmallerThanX: 1
0.99999999999999989
Sigmoid is smaller than firstSmallerThanY: 1
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加