系统: win10

环境:Anaconda+Spyder+python3.7

安装:

tensorflow2.0测试

有如下输出,证明TensorFlow配置好GPU了,就可以正常使用。下面的警告不用在意,因为我们定义了一个tf的空函数做测试。

(tf2.0) C:\Users\DELL>python
Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> @tf.function
... def f():
...     pass
...
>>> f()
2019-07-09 14:07:29.147875: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library nvcuda.dll
2019-07-09 14:07:29.560746: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
name: GeForce 930M major: 5 minor: 0 memoryClockRate(GHz): 0.941
pciBusID: 0000:01:00.0
2019-07-09 14:07:29.577729: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-07-09 14:07:29.587091: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2019-07-09 14:07:29.595647: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-07-09 14:07:29.611393: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
name: GeForce 930M major: 5 minor: 0 memoryClockRate(GHz): 0.941
pciBusID: 0000:01:00.0
2019-07-09 14:07:29.626317: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-07-09 14:07:29.641810: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2019-07-09 14:07:31.708220: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-07-09 14:07:31.715133: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0
2019-07-09 14:07:31.719165: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N
2019-07-09 14:07:31.724416: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1390 MB memory) -> physical GPU (device: 0, name: GeForce 930M, pci bus id: 0000:01:00.0, compute capability: 5.0)
WARNING: Logging before flag parsing goes to stderr.
W0709 14:07:31.761242  4164 ag_logging.py:145] Entity <function f at 0x00000202991AC268> could not be transformed and will be executed as-is. Please report this to the AutoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: converting <function f at 0x00000202991AC268>: ValueError: Unable to locate the source code of <function f at 0x00000202991AC268>. Note that functions defined in certain environments, like the interactive Python shell do not expose their source code. If that is the case, you should to define them in a .py source file. If you are certain the code is graph-compatible, wrap the call using @tf.autograph.do_not_convert. Original error: could not get source code
WARNING: Entity <function f at 0x00000202991AC268> could not be transformed and will be executed as-is. Please report this to the AutoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: converting <function f at 0x00000202991AC268>: ValueError: Unable to locate the source code of <function f at 0x00000202991AC268>. Note that functions defined in certain environments, like the interactive Python shell do not expose their source code. If that is the case, you should to define them in a .py source file. If you are certain the code is graph-compatible, wrap the call using @tf.autograph.do_not_convert. Original error: could not get source code

实验题目:

The problem we will solve is to convert from Celsius to Fahrenheit, where the approximate formula is:

Of course, it would be simple enough to create a conventional Python function that directly performs this calculation, but that wouldn't be machine learning.

Instead, we will give TensorFlow some sample Celsius values (0, 8, 15, 22, 38) and their corresponding Fahrenheit values (32, 46, 59, 72, 100).
Then, we will train a model that figures out the above formula through the training process.

设计和训练一个很简单的神经网络,给出一组输入数据(摄氏度)和输出数据(华氏度)用来训练神经网络。本质上就是做函数拟合,实际效果很好(单神经元),后面又训练了一个三层神经网络作比较。

神经网络架构:

实验代码:

具体的注释就不写了,学过神经网络的应该很容易理解。当然如果有疑问的话可以评论,我看到会及时回答。

# -*- coding: utf-8 -*-
"""
Created on Tue Jul  9 13:37:20 2019@author: Happyhui
"""
import tensorflow as tf
import numpy as npprint(tf.__version__)import logging
logger = tf.get_logger()
logger.setLevel(logging.ERROR)# Set up training data
celsius_q    = np.array([-40, -10,  0,  8, 15, 22,  38],  dtype=float)
fahrenheit_a = np.array([-40,  14, 32, 46, 59, 72, 100],  dtype=float)
for i,c in enumerate(celsius_q):print("{} degrees Celsius = {} degress Fahrenheit".format(c, fahrenheit_a[i]))# Create the model
# Build a layer
L0 = tf.keras.layers.Dense(units = 1, input_shape=[1])
# Assemble layers into the model
model = tf.keras.Sequential([L0])# Compile the model, with loss and optimizer functions
model.compile(loss='mean_squared_error',optimizer=tf.keras.optimizers.Adam(0.1) )# Train the model
history = model.fit(celsius_q, fahrenheit_a, epochs=500, verbose=False)
print("Finished training the model")# Display training statistics
import matplotlib.pyplot as pltplt.xlabel('Epoch Number')
plt.ylabel("Loss Magnitude")
plt.plot(history.history['loss'])# Use the model to predict values
print(model.predict([100.0]))
# Looking at the layer weights
print("These are the layer variables: {}".format(L0.get_weights()))# A little experiment
# Just for fun, what if we created more Dense layers with different units,
#  which therefore also has more variables?
L0 = tf.keras.layers.Dense(units=4, input_shape=[1])
L1 = tf.keras.layers.Dense(units=4)
L2 = tf.keras.layers.Dense(units=1)
model = tf.keras.Sequential([L0, L1, L2])
model.compile(loss='mean_squared_error', optimizer=tf.keras.optimizers.Adam(0.1))
model.fit(celsius_q, fahrenheit_a, epochs=500, verbose=False)
print("Finished training the model")
print(model.predict([100.0]))
print("Model predicts that 100 degrees Celsius is: {} degrees Fahrenheit".format(model.predict([100.0])))
print("These are the L0 variables: {}".format(L0.get_weights()))
print("These are the L1 variables: {}".format(L1.get_weights()))
print("These are the L2 variables: {}".format(L2.get_weights()))

实验结果:

TensorFlow 2.0.0(TensorFlow1.xx也可以用)+ Kears 测试、入门例程 (摄氏度-华氏度转换 )相关推荐

  1. Ubuntu16.04下CUDA 9.0 + cuDNN v7.0 + tensorflow 1.6.0(GPU)环境搭建

    由于自己攒了个主机,第一次安装GPU版本的tensorflow,mark一下. 说明一下,本篇上接<Ubuntu16.04LTS下搭建强化学习环境gym.tensorflow>这篇文章,只 ...

  2. ERROR: Cannot install keras==2.2.0 and tensorflow==1.14.0 because these package versions have confli

    ERROR: Cannot install keras2.2.0 and tensorflow1.14.0 because these package versions have conflictin ...

  3. (Win10)基于Anaconda的 Tensorflow 1.15.0 安装教程

    目录 1.寻找匹配版本 2. 安装CUDA+cuDNN 2.1 安装VS 2017 2.2更新显卡驱动 2.3 CUDA 10.0安装 2.4 cuDDN7.4安装 2.5 环境变量 2.6测试CUD ...

  4. TensorFlow 1.8.0正式发布,Bug修复和改进内容都在这里了

    译者 | 王柯凝 编辑 | Just 出品 | AI科技大本营(公众号ID:rgznai100) [导语]TensorFlow 1.8.0 近日正式发布,新版本主要有以下改进内容,AI科技大本营对其编 ...

  5. TensorFlow 1.7.0正式发布,Bug修复和改进内容都在这里了

    编译 | AI科技大本营(公众号ID:rgznai100) 参与 | 张建军 TensorFlow 1.7.0 近日正式发布,新版本主要有以下改进内容,AI科技大本营对其进行了编译. 主要特征和改进 ...

  6. TensorFlow 1.13.0 正式发布,谷歌开源的机器学习框架

    TensorFlow 1.13.0 已正式发布,TensorFlow 是谷歌的第二代机器学习系统,按照谷歌所说,在某些基准测试中,TensorFlow 的表现比第一代的 DistBelief 快了 2 ...

  7. MobaXterm 设置在使用export DISPLAY=xx.xx.xx.xx:0.0后调用图形化界面不弹出提示方法

    设置 export DISPLAY=xx.xx.xx.xx:0.0 后,每次调用图形化界面前都会有下面的提示. 只要在设置里,将 X11 remote access 设置为 full,以后就不会弹出了 ...

  8. Tensorflow2.0与Tensorflow1.x不兼容问题

    Tensorflow2.0与Tensorflow1.x不兼容问题_xiaohui2014的博客-CSDN博客

  9. TensorFlow 2.1.0 来了,重大更新与改进了解一下

    By 超神经 导读:2019 年 11 月末,TensorFlow 的官方 GitHub 账号发布了 TensorFlow 2.1.0-rc  版本,现在,官方最新发布了 TensorFlow 2.1 ...

最新文章

  1. 基于 OpenCV 的图像分割项目实战
  2. 11月24日struts培训日记
  3. 打开360浏览器显示无法连接服务器错误,Win10电脑上360浏览器提示网络连接错误,错误代码 102的解决方案...
  4. CoSENT:特征式匹配与交互式匹配有多大差距?
  5. Webservice初接触
  6. c++中的类型转换--reinterpret_cast
  7. pom模块依赖关系梳理
  8. asp.net922-基于Web的房屋中介管理信息系统
  9. 全局鼠标手势linux,Firefox通过用户脚本和热键进行的全局鼠标手势(Win7 / Linux + FF 68 esr)...
  10. 沈从文写给张兆和的情书
  11. 电饭锅面包的做法大全 电饭锅怎么做面包
  12. 数据库原理第一章测验(标黑的为答案)
  13. [附源码]java+ssm计算机毕业设计java交通违章举报平台lxsqm【源码、数据库、LW、部署】
  14. 服务器怎么使用无线网卡,无线上网卡怎么用
  15. 社交网站需要多大的服务器空间,社交app选多大云服务器
  16. 边缘设备、系统及计算杂谈(13)——k8s学习之三
  17. oracle dbms advisor,通过shell定制dbms_advisor.quick_tune
  18. vm中装linux换iso文件报错该光盘无法被挂载,虚拟机VMware下安装RedHat Linux 9.0 图解教程...
  19. Android安卓集成融云推送踩坑
  20. mac报错: vue-cli-service: command not found

热门文章

  1. Android 微信摇一摇功能实现
  2. MySQL 索引的数据结构及优化实战
  3. 信号归一化功率_利用电机的电信号来检测轴承性能退化
  4. typedef enum与enum的用法
  5. IMB X3650配置RAID
  6. 流技术安全系统-流量流向监控技术
  7. 公众号一键拨打400服务电话
  8. fusion app 网页远程控制app
  9. Appium抓取app数据
  10. Windows Server 2003自带NAT功能,轻松实现不同网段互访