首页 技术 正文
技术 2022年11月20日
0 收藏 681 点赞 4,319 浏览 796 个字

TensorFlow 是谷歌开发的机器学习框架。

安装 TensorFlow

直接使用 pip 安装即可,添加豆瓣镜像可以加快速度:

pip install tensorflow -i https://pypi.douban.com/simple

如果有 GPU 可以充分利用,安装:

pip install tensorflow-gpu -i https://pypi.douban.com/simple

目前我使用的 TensorFlow 版本是  tensorflow==1.14. ,目前 TensorFlow 不支持 3.7 及以上的版本。我的 Python 版本使用的是 3.6

认识 TensorFlow 包

TensorFlow 包有两个主要的目录:corecontrib。core 是包含核心模块的目录,contrib 是尚未归入到 core 的目录(可能随时会归入)。

认识其中重要的包名:

  • tensorflow:TensorFlow 的主包
  • tf.train:优化器、与训练有关的类
  • tf.nn:神经网络类及其数学运算
  • tf.layer:多层神经网络的相关函数
  • tf.contrib:包含不稳定或者实验性的代码
  • tf.image:图像处理函数
  • tf.estimator:提供训练和评估的高级抽象的工具
  • tf.logging:记录日志的工具
  • tf.summary:生成总结的工具
  • tf.metrics:评估机器学习结果的函数

跑一个 TensorFlow 应用

说了这么多,写点实际的代码跑一下 TensorFlow 应用。

 import tensorflow as tf # 创建一个张量
msg = tf.string_join(["Hello ", "TensorFlow!"])
# 发起一个会话
with tf.Session() as sess:
print(sess.run(msg))

输出:

b'Hello TensorFlow!'

TensorFlow 中张量用于存储数据,而会话用于真正执行数据运算操作。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,035
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,521
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,369
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,150
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,783
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,865