线性回归-clip_gradients_by_norm-语法无效

时间:2018-07-25 13:30:21

标签: tensorflow linear-regression gradient-descent clip

04和python 3.6

我安装了应用程序Tensor Flow,但我不理解系统检测到的错误。 我写道:

 my_optimizer=tf.train.GradientDescentOptimizer(learning_rate=0.0000001)

 my_optimizer = tf.contrib.estimator.clip_gradients_by_norm(my_optimizer, 5.0)

第一行工作正常,但第二行系统给出:

Traceback (most recent call last):
 File "/home/hal9500/Bureau/essai1.py", line 43, in <module>
  my_optimizer= tf.contrib.estimator.clip_gradients_by_norm(my_optimizer,5.0)
   File "/home/hal9500/.local/lib/python3.6/site-packages/tensorflow/python/util/lazy_loader.py", line 53, in __getattr__
module = self._load()
File "/home/hal9500/.local/lib/python3.6/site-packages/tensorflow/python/util/lazy_loader.py", line 42, in _load
module = importlib.import_module(self.__name__)
File "/home/hal9500/anaconda3/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/hal9500/.local/lib/python3.6/site-packages/tensorflow/contrib  /__init__.py", line 47, in <module>
from tensorflow.contrib import image
File "/home/hal9500/.local/lib/python3.6/site-packages/tensorflow/contrib/image/__init__.py", line 70, in <module>
from tensorflow.contrib.image.python.ops.single_image_random_dot_stereograms import single_image_random_dot_stereograms
 File "/home/hal9500/.local/lib/python3.6/site-packages/tensorflow/contrib/image/python/ops/single_image_random_dot_stereograms.py", line 27, in <module>
"_single_image_random_dot_stereograms.so"))
File "/home/hal9500/.local/lib/python3.6/site-packages/tensorflow/contrib/util/loader.py", line 56, in load_op_library
ret = load_library.load_op_library(path)
 File "/home/hal9500/.local/lib/python3.6/site-packages/tensorflow/python/framework/load_library.py", line 73, in load_op_library
exec(wrappers, module.__dict__)
 File "<string>", line 27
def single_image_random_dot_stereograms(depth_values, hidden_surface_removal=True, convergence_dots_size=8, dots_per_inch=72, eye_separation=2,5, mu=0,333299994, normalize=True, normalize_max=-100, normalize_min=100, border_level=0, number_colors=256, output_image_shape=[1024, 768, 1], output_data_window=[1022, 757], name=None):
                                                                                                                                                      ^
SyntaxError: invalid syntax                                                                                                                 

如何解决此语法错误?

先谢谢您

1 个答案:

答案 0 :(得分:0)

这是Tensorflow Python API与en_US-UTF8以外的语言环境一起可能发生的错误。似乎发生的是,当Tensorflow Python API从Tensorflow C ++后端调用函数时,使用了错误的小数点格式。 请参阅this Github问题。

一种快速的解决方法是在其他导入语句后的后面插入以下代码:

import locale
locale.setlocale(locale.LC_ALL, locale="en_US.UTF-8")

非常感谢用户hofingermarkus共享此替代方法。