【问题标题】:Tensorflow eager no kerasTensorFlow 渴望没有 keras
【发布时间】:2018-09-19 12:41:44
【问题描述】:

没有 keras 可以在 tensorflow 中进行急切执行吗?我在 TensorFlow 图形代码中有一个非神经网络模型可以转移到 Eager。这是推荐系统的低秩矩阵分解。

Python 语言。

谢谢

要求回答者演示工作代码。如果答案包括推测,请明确说明。

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    是的,您当然可以在不使用 Keras 的情况下使用 Eager Execution。 Keras 建立在支持 Eager Execution 的较低级别操作之上。

    例如:

    import tensorflow as tf
    import numpy as np
    tf.enable_eager_execution()
    
    W = tf.contrib.eager.Variable(tf.random_normal((10, 10)))
    
    def model(x):
      return tf.matmul(x, W)
    
    data = np.random.randn(3, 10).astype(np.float32)
    print(model(data))
    

    你可以在https://www.tensorflow.org/tutorials/eager/看到一些更详细的教程

    也就是说,如果尝试运行为构建启用了急切执行的图形而编写的任意代码,您可能会遇到各种极端情况/错误,并且可能需要进行轻微的重构。这些将取决于代码结构的细节。

    反之(即编写启用急切执行的代码)通常可以在未启用急切执行时很好地构建等效图。

    希望对您有所帮助。

    【讨论】:

    • 如何在不使用 keras 模型概念的情况下以 Eager 模式训练模型?
    猜你喜欢
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    • 2013-05-06
    • 2014-05-15
    • 1970-01-01
    • 2018-11-05
    • 2013-12-20
    • 1970-01-01
    相关资源
    最近更新 更多