深度学习TensorFlow1

1:TensorFlow特点:

1:高度灵活:不仅可以用来作神经网络算法研究,也可以用来作普通机器学习算法,甚至是只要把计算表示成数据流图,都可以用TensorFlow。

2:语言多样:基于C++实现,使用python封装。

3:设备支持:允许GPU和CPU上计算分布。

4:可视化:TensorBoard支持五种可视化:标量,图片,音频,直方图,计算图。

2:Tensorflow结构分析

TensorFlow程序通常被组织成一个构件图阶段和一个执行图阶段。

在构建阶段,数据与操作的执行步骤被描述成一个图。

在执行阶段,使用会话执行构建好的图中的的操作

1:图和会话:

        图:这是TensorFlow将计算表示为指令之间依赖关系的一种表示法

       会话:TensorFlow跨一个或多个本地或远程设备进行数据流图的机制

       张量:TensorFlow中的基本数据对象

       节点:提供图当中执行的操作

TensorFlow是一个采用数据流图,用于数值计算的开源框架。

节点在图中表示数学操作,线则表示节点间相互联系的多维数据,即张量。

下面举一个最简单的加法例子,直接上代码

import  tensorflow as tf

tf.compat.v1.disable_eager_execution()

def tensorflow_demo():
    #原生加法
    a = 2
    b = 3
    c = a+b
    print("普通加法运算的结果:\n",c)

    #tf加法运算
    a_t = tf.constant(2)
    b_t = tf.constant(3)
    c_t = a_t + b_t
    print("TensorFlow加法运算的结果:\n",c_t)

   #开启会话
    with tf.compat.v1.Session() as sess:
        c_t_values = sess.run(c_t)
        print(c_t_values)

tensorflow_demo()

我看的学习视频里 由于版本之间的差异,一些语法在新的版本中无法适用,于是便根据报错内容上网搜查改正了语法。我目前使用的版本是python 3.9,TensorFlow 2.5.0。

2021-07-02 22:09:10.686093: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-07-02 22:09:10.686273: 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.
普通加法运算的结果:
 5
TensorFlow加法运算的结果:
 Tensor("add:0", shape=(), dtype=int32)
2021-07-02 22:09:12.108886: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library nvcuda.dll
2021-07-02 22:09:12.134151: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1733] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1650 Ti computeCapability: 7.5
coreClock: 1.485GHz coreCount: 16 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 178.84GiB/s
2021-07-02 22:09:12.135275: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-07-02 22:09:12.136853: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublas64_11.dll'; dlerror: cublas64_11.dll not found
2021-07-02 22:09:12.138435: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublasLt64_11.dll'; dlerror: cublasLt64_11.dll not found
2021-07-02 22:09:12.142061: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2021-07-02 22:09:12.143396: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2021-07-02 22:09:12.144825: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusolver64_11.dll'; dlerror: cusolver64_11.dll not found
2021-07-02 22:09:12.145969: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusparse64_11.dll'; dlerror: cusparse64_11.dll not found
2021-07-02 22:09:12.146992: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
2021-07-02 22:09:12.147156: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1766] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2021-07-02 22:09:12.147725: 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:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-07-02 22:09:12.148442: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1258] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-07-02 22:09:12.148571: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1264]      
5

进程已结束,退出代码为 0

每次运行都会报上述红字,查阅资料好像与GPU相关,我是直接在pycharm上安装的,应该是只与CPU有关。

你可能感兴趣的:(机器学习,深度学习)