Mac下anaconda3启动tensorflow和tensorboard

启动tensorflow:

cd /
cd anaconda3/
bin/jupyter-notebook

启动tensorboard:

cd /
cd anaconda3/
tensorboard --logdir=log/02
或者是启动指定的日志文件02

在python代码中需要写入log文件:

import tensorflow as tf
tf.reset_default_graph()
logdir = "/anaconda3/log/01"
 
input1 = tf.constant([1.0,2.0,3.0],name="input1")
input2 = tf.Variable(tf.random_uniform([3]),name="input2")
output = tf.add_n([input1,input2],name = "add")


writer = tf.summary.FileWriter(logdir,tf.get_default_graph())
writer.close()
# -*- coding: UTF-8 -*-
# 引入tensorflow
import tensorflow as tf
# 设置了gpu加速提示信息太多了,设置日志等级屏蔽一些
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='3'
# 构造图(Graph)的结构
# 用一个线性方程的例子 y = W * x + b
# 梯度下降法求w和b
W = tf.Variable(2.0, dtype=tf.float32, name="Weight") 
# 权重
b = tf.Variable(1.0, dtype=tf.float32, name="Bias") 
# 偏差
x = tf.placeholder(dtype=tf.float32, name="Input") 
# 输入
with tf.name_scope("Output"):      
    # 输出的命名空间
    y = W * x + b    
    # 输出#
    const = tf.constant(2.0) 
    # 常量,不需要初始化# 定义保存日志的路径
    path = "/anaconda3/log/02"
    # 创建用于初始化所有变量 (Variable) 的操作
    init = tf.global_variables_initializer()
    # 创建Session(会话)
    with tf.Session() as sess:
        sess.run(init) 
        # 初始化变量
        # 写入日志文件
        writer = tf.summary.FileWriter(path, sess.graph)    # 因为x是一个placeholder,需要进行值的填充
        result = sess.run(y, {x: 3.0})
        print("y = %s" % result) # 打印 y = W * x + b 的值,就是 7

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值