【深度学习入门】tensorflow安装及入门

tensorflow安装及入门

一、环境
python3.5版本、pycharm。

二、关于tensorflow的安装方法

方式一:在有网络状态下,
在线安装打开命令行 pip install tensorflow 。

方法二:在有网络状态下,
在pycharm内部,setting设置,添加包。

方式三:离线安装,
下载tensorflow.whl,离线安装。对应的依赖whl也需要下载在本地。(同一级目录下就行)

三、检测是否安装成功

1、打开命令行 pip show tenwsorflow 命令,
查看是否有tensorflow的相关版本、存储位置等信息。

2、之后进入python环境输入命令 import tenwsorflow
如果没有报错,证明安装成功。

四、tensorflow的基础应用

1、字符串使用

import tensorflow as
tf

hello =
tf.constant('Hello, TensorFlow!')#定义常量

# Start tf session

sess = tf.Session()

print
(sess.run(hello))

在这里插入图片描述

2、矩阵使用

import tensorflow as
tf

matrix2 =
tf.constant([[2.],[2.]])

matrix1 =
tf.constant([[3., 3.]])

product =
tf.matmul(matrix1, matrix2)

with tf.Session() as
sess:

    result = sess.run(product)

print (result)

在这里插入图片描述

3、变量使用

import tensorflow as
tf

state = tf.Variable(0)

one = tf.constant(1)

update =
tf.assign(state, tf.add(state, one))

with tf.Session() as
sess:

    sess.run(tf.initialize_all_variables())

    print(sess.run(state))

    for _ in range(3):

        sess.run(update)

        print(sess.run(state))

在这里插入图片描述

制作人:只识闲人不识君

日期:2020.05.17

猜你喜欢

转载自blog.csdn.net/weixin_46069678/article/details/106169592
今日推荐