【问题标题】:Error in tensorflow for R exampleR示例的张量流错误
【发布时间】:2019-01-30 05:52:15
【问题描述】:

我是 TensorFlow 的新手。我听说 R 的 tensorflow 接口真的很棒。但是我发现很难运行此处列出的示例:https://tensorflow.rstudio.com/tensorflow/articles/examples/linear_regression_multiple.html

具体问题在以下几行

while (TRUE) {
+     session$run(optimizer, feed_dict = feed_dict)
+     current_cost <- session$run(cost, feed_dict = feed_dict)
+     if (last_cost - current_cost < epsilon) break
+     last_cost <- current_cost
+ }

这会引发以下错误:

Error in py_call_impl(callable, dots$args, dots$keywords) : 
  TypeError: Fetch argument <tensorflow.python.training.gradient_descent.GradientDescentOptimizer object at 0x126eaaf50> of <tensorflow.python.training.gradient_descent.GradientDescentOptimizer object at 0x126eaaf50> has invalid type <class 'tensorflow.python.training.gradient_descent.GradientDescentOptimizer'>, must be a string or Tensor. (Can not convert a GradientDescentOptimizer into a Tensor or Operation.)

我从上面的例子中唯一改变的是:

tf$global_variables_initializer

tf$initialize_all_variables

有人遇到过类似的错误吗?

【问题讨论】:

    标签: python r tensorflow rstudio


    【解决方案1】:

    tensorflow 中已弃用 initialize_all_variables API(并于 2017-03-02 删除),正确使用的 API 是 global_variables_initializer

    https://www.tensorflow.org/api_docs/python/tf/initialize_all_variables

    【讨论】:

    • 我可能有一个旧版本。因为当我运行它时,我得到: py_get_attr_impl(x, name, quiet) 中的错误:AttributeError: 'module' object has no attribute 'global_variables_initializer'
    猜你喜欢
    • 2018-05-04
    • 2018-06-21
    • 2016-06-27
    • 2017-08-04
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 2018-07-21
    • 1970-01-01
    相关资源
    最近更新 更多