EffectiveTensorflow:Tensorflow 教程和最佳实践

Tensorflow和其他数字计算库(如numpy)之间最明显的区别在于Tensorflow中的操作是符号。 这是一个强大的概念,允许Tensorflow进行所有类型的事情(例如自动区分),这些命令式的库(例如numpy)是不可能的。 但它也是以更难掌握为代价的。 我们在这里的尝试揭示了Tensorflow,并为更有效地使用Tensorflow提供了一些指导方针和最佳实践。

The most striking difference between Tensorflow and other numerical computation libraries such as numpy is that operations in Tensorflow are symbolic. This is a powerful concept that allows Tensorflow to do all sort of things (e.g. automatic differentiation) that are not possible with imperative libraries such as numpy. But it also comes at the cost of making it harder to grasp. Our attempt here is demystify Tensorflow and provide some guidelines and best practices for more effective use of Tensorflow.

Let’s start with a simple example, we want to multiply two random matrices. First we look at an implementation done in numpy:

[code lang=text]
import numpy as np

x = np.random.normal(size=[10, 10])
y = np.random.normal(size=[10, 10])
z = np.dot(x, y)

print(z)
[/code]

Now we perform the exact same computation this time in Tensorflow:

[code lang=text]
import tensorflow as tf

x = tf.random_normal([10, 10])
y = tf.random_normal([10, 10])
z = tf.matmul(x, y)

sess = tf.Session()
z_val = sess.run(z)

print(z_val)
[/code]

项目地址:https://github.com/vahidk/EffectiveTensorflow

Related posts

Leave a Comment