First Steps with TensorFlow

本文介绍了TensorFlow的基础结构及Estimator API的使用方法。Estimator API与scikit-learn兼容,简化了机器学习模型的训练和预测过程。通过一个线性回归的例子展示了如何创建模型、训练数据以及进行预测。

1.First Steps with TensorFlow: Toolkit

下图是TensorFlow工具包的结构层次图:

                          

下表总结了不同层的用途:

工具包说明
Estimator (tf.estimator)高级 OOP API。
tf.layers/tf.losses/tf.metrics用于常见模型组件的库。
TensorFlow低级 API

TensorFlow 由以下两个组件组成:

  • 图协议缓冲区(graph protocol buffer)
  • 执行(分布式)图的运行时(a runtime that executes the (distributed) graph)
这两个组件类似于 Java 编译器和 JVM。正如 JVM 会实施在多个硬件平台(CPU 和 GPU)上一样,TensorFlow 也是如此。

较高级别的API更易于使用,但(设计方面)不够灵活。

(1)tf.estimator API-最高层

tf.estimator 与 scikit-learn API 兼容。scikit-learn是极其热门的 Python 开放源代码机器学习库。

以下是在 tf.estimator 中实现的线性回归程序的格式:

import tensorflow as tf

# Set up a linear classifier.
classifier = tf.estimator.LinearClassifier()

# Train the model on some example data.
classifier.train(input_fn=train_input_fn, steps=2000)

# Use it to predict.
predictions = classifier.predict(input_fn=predict_input_fn)
Key Terms
Estimators 估计量graph
tensor 张量

### TensorFlow Installation Guide for Python 3.8 For installing TensorFlow with Python 3.8, it is important to ensure compatibility and follow a structured approach as outlined below: To begin the installation process of TensorFlow compatible with Python 3.8, one should first verify that the correct version of Python is installed since TensorFlow supports specific versions including Python 3.8 up until more recent releases[^2]. Once the environment setup confirms Python 3.8 availability, proceed by creating an isolated virtual environment specifically tailored for this project or application using tools like `venv` which comes bundled with Python. After setting up the virtual environment, activate it before proceeding further. This ensures all package installations are contained within this sandboxed area without affecting system-wide packages or configurations. With the virtual environment activated, use pip—the Python package installer—to download and set up TensorFlow along with its dependencies suitable for Python 3.8 environments. It's advisable to specify the exact version of TensorFlow known to support Python 3.8 during installation commands such as shown here: ```bash pip install tensorflow==2.5.0 ``` This command installs TensorFlow version 2.5.0, which has been confirmed to work well with Python 3.8 according to historical release notes and community feedback. Additionally, when working under constraints where internet access might be limited or speed becomes critical, consider utilizing alternative PyPI mirrors provided by institutions like Tsinghua University for faster downloads via pip commands similar to those used for other libraries mentioned elsewhere[^4]. Finally, after completing these steps successfully, validate the installation through simple test scripts ensuring basic functionalities operate correctly under Python 3.8 alongside newly installed TensorFlow components.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值