简体   繁体   English

Tensorflow渴望没有keras

[英]Tensorflow eager no keras

With NO keras can you do eager execution in tensorflow? 使用NO keras,您可以在tensorflow中渴望执行吗? I have a non-neural network model in TensorFlow graph code to move to eager. 我在TensorFlow图形代码中有一个非神经网络模型,因此急于转向。 This is a low rank matrix factorization for recommender system. 这是推荐系统的低秩矩阵分解。

Python language. Python语言。

Thank you 谢谢

Request that answerers please demonstrate working code. 要求答题者演示操作代码。 If answer includes speculation then please state explicitly. 如果答案包括猜测,请明确说明。

Yes, you can certainly use eager execution without Keras. 是的,没有Keras,您当然可以使用急切的执行。 Keras is built on top of the lower level operations that support eager execution. Keras建立在支持热切执行的低层操作之上。

For example: 例如:

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))

You can see some more detailed tutorials at https://www.tensorflow.org/tutorials/eager/ 您可以在https://www.tensorflow.org/tutorials/eager/上看到一些更详细的教程。

That said, there are various corner cases/errors you might hit if trying to run arbitrary code written to construct a graph with eager execution enabled, and slight refactoring may be needed. 就是说,如果尝试运行编写的代码以构建启用了急切执行的图形的任意代码,可能会遇到各种极端情况/错误,并且可能需要进行一些重构。 Those would depend on the details of how the code is structured. 这些将取决于代码的结构细节。

The reverse (ie, writing code that works with eager execution enabled) generally works out well to construct the equivalent graph when eager execution is not enabled. 相反(即,编写启用了急切执行的代码)通常可以很好地构造出当未启用急切执行时的等效图。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM