人工智能深度学习入门练习之(23)TensorFlow2基础语法之练习
发布日期:2021-05-14 00:18:28 浏览次数:24 分类:博客文章

本文共 4304 字,大约阅读时间需要 14 分钟。

1���������������

������tensorflow1.x���
import tensorflow.compat.v1 as tftf.disable_v2_behavior() # ���������������������������������������assert tf.__version__.startswith('2.')# 1.���������������������# ������2���������������������������������������a_ph = tf.placeholder(tf.float32, name='variable_a')b_ph = tf.placeholder(tf.float32, name='variable_b')# ���������������������������������������������c_op = tf.add(a_ph, b_ph, name='variable_c')# 2.���������������������# ������������������sess = tf.InteractiveSession()# ������������������������������������������init = tf.global_variables_initializer()sess.run(init) # ���������������������������������������# ������������������������������������������������c_numpy = sess.run(c_op, feed_dict={a_ph: 2., b_ph: 4.})# ������������������������������������������������c_numpyprint('a+b=',c_numpy)

���������

C:\Anaconda3\python.exe "C:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pydev\pydevconsole.py" --mode=client --port=63269import sys; print('Python %s on %s' % (sys.version, sys.platform))sys.path.extend(['C:\\app\\PycharmProjects', 'C:/app/PycharmProjects'])Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]Type 'copyright', 'credits' or 'license' for more informationIPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.PyDev console: using IPython 7.12.0Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] on win32runfile('C:/app/PycharmProjects/tensorflow/Test/__init__.py', wdir='C:/app/PycharmProjects/tensorflow/Test')2020-11-10 15:25:43.753169: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found2020-11-10 15:25:43.755830: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.WARNING:tensorflow:From C:\Anaconda3\lib\site-packages\tensorflow\python\compat\v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.Instructions for updating:non-resource variables are not supported in the long term2020-11-10 15:26:07.126862: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.2020-11-10 15:26:07.199289: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1ccbe5249e0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:2020-11-10 15:26:07.201115: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version2020-11-10 15:26:07.206639: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found2020-11-10 15:26:07.209239: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)a+b= 6.0
������tensorflow2.x���
import tensorflow as  tfa=tf.constant(2.0)b=tf.constant(4.0)print('{0}+{1}={2}'.format(a,b,a+b))

���������

C:\Anaconda3\python.exe "C:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pydev\pydevconsole.py" --mode=client --port=63589import sys; print('Python %s on %s' % (sys.version, sys.platform))sys.path.extend(['C:\\app\\PycharmProjects', 'C:/app/PycharmProjects'])Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]Type 'copyright', 'credits' or 'license' for more informationIPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.PyDev console: using IPython 7.12.0Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] on win32runfile('C:/app/PycharmProjects/tensorflow/Test/__init__.py', wdir='C:/app/PycharmProjects/tensorflow/Test')2020-11-10 15:46:36.564267: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found2020-11-10 15:46:36.566052: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.2.0+4.0=6.0

 

上一篇:大数据集群运维(65)tensorflow-gpu在win10下的安装教程
下一篇:Java从入门到实战之(30)Java 字符串方法之总结

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年05月03日 23时32分57秒