Tensorflow 简明教程

TensorFlow - TFLearn And Its Installation

TFLearn 可定义为用于 TensorFlow 框架的模块化和透明的深度学习环节。TFLearn 的主要目的为 TensorFlow 提供高级的 API 以实现新实验。

TFLearn can be defined as a modular and transparent deep learning aspect used in TensorFlow framework. The main motive of TFLearn is to provide a higher level API to TensorFlow for facilitating and showing up new experiments.

考虑 TFLearn 的以下重要特质 −

Consider the following important features of TFLearn −

  1. TFLearn is easy to use and understand.

  2. It includes easy concepts to build highly modular network layers, optimizers and various metrics embedded within them.

  3. It includes full transparency with TensorFlow work system.

  4. It includes powerful helper functions to train the built in tensors which accept multiple inputs, outputs and optimizers.

  5. It includes easy and beautiful graph visualization.

  6. The graph visualization includes various details of weights, gradients and activations.

执行以下命令安装 TFLearn −

Install TFLearn by executing the following command −

pip install tflearn

执行以上代码后,将生成以下输出 −

Upon execution of the above code, the following output will be generated −

install tflearn

下图显示了 TFLearn 与 Random Forest 分类程序的实现 −

The following illustration shows the implementation of TFLearn with Random Forest classifier −

from __future__ import division, print_function, absolute_import

#TFLearn module implementation
import tflearn
from tflearn.estimators import RandomForestClassifier

# Data loading and pre-processing with respect to dataset
import tflearn.datasets.mnist as mnist
X, Y, testX, testY = mnist.load_data(one_hot = False)

m = RandomForestClassifier(n_estimators = 100, max_nodes = 1000)
m.fit(X, Y, batch_size = 10000, display_step = 10)

print("Compute the accuracy on train data:")
print(m.evaluate(X, Y, tflearn.accuracy_op))

print("Compute the accuracy on test set:")
print(m.evaluate(testX, testY, tflearn.accuracy_op))

print("Digits for test images id 0 to 5:")
print(m.predict(testX[:5]))

print("True digits:")
print(testY[:5])