- Mastering TensorFlow 1.x
- Armando Fandango
- 307字
- 2021-06-25 22:51:01
PrettyTensor
PrettyTensor provides a thin wrapper on top of TensorFlow. The objects provided by PrettyTensor support a chainable syntax to define neural networks. For example, a model could be created by chaining the layers as shown in the following code:
model = (X.
flatten().
fully_connected(10).
softmax_classifier(n_classes, labels=Y))
PrettyTensor can be installed in Python 3 with the following command:
pip3 install prettytensor
PrettyTensor offers a very lightweight and extensible interface in the form of a method named apply(). Any additional function can be chained to PrettyTensor objects using the .apply(function, arguments) method. PrettyTensor will call the function and supply the current tensor as the first argument to the function.
User-created functions can be added using the @prettytensor.register decorator. Details can be found at https://github.com/google/prettytensor.
The workflow to define and train models in PrettyTensor is as follows:
- Get the data.
- Define hyperparameters and parameters.
- Define the inputs and outputs.
- Define the model.
- Define the evaluator, optimizer, and trainer functions.
- Create the runner object.
- Within a TensorFlow session, train the model with the runner.train_model() method.
- Within the same session, evaluate the model with the runner.evaluate_model() method.
The complete code for the PrettyTensor MNIST classification example is provided in the notebook ch-02_TF_High_Level_Libraries. The output from the PrettyTensor MNIST example is as follows:
[1] [2.5561881] [600] [0.3553167] Accuracy after 1 epochs 0.8799999952316284 [601] [0.47775066] [1200] [0.34739292] Accuracy after 2 epochs 0.8999999761581421 [1201] [0.19110668] [1800] [0.17418651] Accuracy after 3 epochs 0.8999999761581421 [1801] [0.27229539] [2400] [0.34908807] Accuracy after 4 epochs 0.8700000047683716 [2401] [0.40000191] [3000] [0.30816519] Accuracy after 5 epochs 0.8999999761581421 [3001] [0.29905257] [3600] [0.41590339] Accuracy after 6 epochs 0.8899999856948853 [3601] [0.32594997] [4200] [0.36930788] Accuracy after 7 epochs 0.8899999856948853 [4201] [0.26780865] [4800] [0.2911002] Accuracy after 8 epochs 0.8899999856948853 [4801] [0.36304188] [5400] [0.39880857] Accuracy after 9 epochs 0.8999999761581421 [5401] [0.1339224] [6000] [0.14993289] Accuracy after 10 epochs 0.8899999856948853
- 新媒體跨界交互設計
- Linux KVM虛擬化架構實戰指南
- 電腦維護365問
- Creating Flat Design Websites
- 筆記本電腦維修實踐教程
- 微型計算機系統原理及應用:國產龍芯處理器的軟件和硬件集成(基礎篇)
- Managing Data and Media in Microsoft Silverlight 4:A mashup of chapters from Packt's bestselling Silverlight books
- IP網絡視頻傳輸:技術、標準和應用
- Intel FPGA權威設計指南:基于Quartus Prime Pro 19集成開發環境
- USB應用分析精粹:從設備硬件、固件到主機端程序設計
- 計算機應用基礎案例教程(Windows 7+Office 2010)
- 筆記本電腦的結構、原理與維修
- 從企業級開發到云原生微服務:Spring Boot實戰
- Exceptional C++:47個C++工程難題、編程問題和解決方案(中文版)
- Spring Cloud微服務架構開發