mac下安装tensorflow及入门例子
https://www.tensorflow.org/install/install_mac
使用virtualenv安装,virtualenv相当于使tensorflow运行在虚拟机环境下。
需要使用source ~/tensorflow/bin/activate 命令,(我安装在了
source /Users/work/builded/tensorflow/bin/activate,bash下/是硬盘根目录,~/是用户根目录)
命令行变成 (tensorflow)$ 这样,才可以使用 import tensorflow as tf这些
使用ptython运行一个简单的y = -x +1训练模型:
(tensorflow) $ python tftrain.py
import numpy as np
import tensorflow as tf # Model parameters
W = tf.Variable([.3], tf.float32)
b = tf.Variable([-.3], tf.float32)
# Model input and output
x = tf.placeholder(tf.float32)
linear_model = W * x + b
y = tf.placeholder(tf.float32)
# loss
loss = tf.reduce_sum(tf.square(linear_model - y)) # sum of the squares
# optimizer
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)
# training data
x_train = [1,2,3,4]
y_train = [0,-1,-2,-3]
# training loop
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init) # reset values to wrong
for i in range(1000):
sess.run(train, {x:x_train, y:y_train}) # evaluate training accuracy
curr_W, curr_b, curr_loss = sess.run([W, b, loss], {x:x_train, y:y_train})
print("W: %s b: %s loss: %s"%(curr_W, curr_b, curr_loss))
mac下安装tensorflow及入门例子的更多相关文章
- Windows7 64bits下安装TensorFlow CPU版本(图文详解)
不多说,直接上干货! Installing TensorFlow on Windows的官网 https://www.tensorflow.org/install/install_windows 首先 ...
- Windows7 64bits下安装TensorFlow GPU版本(图文详解)
不多说,直接上干货! Installing TensorFlow on Windows的官网 https://www.tensorflow.org/install/install_windows 首先 ...
- python 3.8 下安装 tensorflow 1.14
pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.14.0-py3-none-a ...
- Mac 下安装 MySQL 步骤
安装 MySQL Mac 下安装MySQL推荐去官网下载dmg 版本的,我使用的版本是5.7.30. 如上图所示. 之后就是傻瓜式一键狂点不过需要注意的是,不要关闭下图所示的框框!不要关闭下图所示的框 ...
- Mac 下安装Jenkins
Mac 下安装Jenkins 开始 Jenkins是一个基于Java开发的一种持续集成工具,用于建工持续重复的工作,功能包括: 持续的软件版本发布/测试项目 监控外部调用执行的工作. 近期打算搭建自动 ...
- MAC下安装与配置MySQL
MAC下安装与配置MySQL MAC下安装与配置MySQL 一 下载MySQL 访问MySQL的官网http://www.mysql.com/downloads/ 然后在页面中会看到“MySQL ...
- Mac下安装UPnP Inspector
由于工作中需要用到UPnP Inspector这个工具,而这个工具在windows下安装非常简单,在Mac下安装却很麻烦,在此记录安装流程. 这个工具依赖于两个其他的库:Coherence(一个DLN ...
- Mac下安装Wireshark,双击闪退
Mac OS X上使用Wireshark抓包(http://blog.csdn.net/phunxm/article/details/38590561) Mac下安装Wireshark /Appli ...
- Mac下安装zshell
Mac 下安装zshell 什么是shell 大多数命令行用户接触最多的是Bash,因为Bash是各个版本操作系统(Linux&Mac)的默认shell. 查看当前使用的shell $ ech ...
随机推荐
- Android Activity作为dialog对话框的使用详细介绍
Activity做为Android应用层四大组件的重要组成部分,它的灵活性.可扩性无论是在应用还是游戏方面都得到了广泛应用,本文主要介绍Activity作为dialog对话框 的使用方法进行说明. 本 ...
- JS高级——原型链
构造函数 构造函数是特殊的函数,里面没有returen返回值 new的过程中,会自动将对象返回,不需要return new的过程中,会执行函数中的代码,会将创建的对象赋值给构造函数中的this 基本概 ...
- day11-函数对象、名称空间和作用域
目录 函数对象 函数的嵌套 名称空间和作用域 内置名称空间 全局名称空间 局部名称空间 作用域 全局作用域 局部作用域 global和nonlocal 函数对象 在Python中,一切皆对象,函数也是 ...
- ES6 Array返回只出现一次的元素
234
- 中望CAD VBA检测文件是否存在
Option Explicit Private Declare Function PathFileExists Lib "shlwapi.dll" Alias "Path ...
- Luogu P1256 显示图像
P1256 显示图像 题目描述 古老的显示屏是由N×M个像素(Pixel)点组成的.一个像素点的位置是根据所在行数和列数决定的.例如P(2,1)表示第2行第1列的像素点.那时候,屏幕只能显示黑与白两种 ...
- Luogu P2298 Mzc和男家丁的游戏
Mzc和男家丁的游戏 题目背景 mzc与djn的第二弹. 题目描述 mzc家很有钱(开玩笑),他家有n个男家丁(做过上一弹的都知道).他把她们召集在了一起,他们决定玩捉迷藏.现在mzc要来寻找他的男家 ...
- django访问静态变量的设置
在项目的urls.py文件中 默认urlpatterns是空的列表需要填入url匹配的路由,默认使用static from django.conf.urls import include, url f ...
- 3.2.1 for循环与while循环的基本语法
不停地重复一件事情,时间久了会非常无聊,然后大脑就会由于疲劳而容易入睡. 重复性的劳动会使人疲劳,而计算机不会,只要代码写得正确,计算机就会孜孜不倦地重复工作.在Python中主要有两种形式的循环结构 ...
- net core 配置Redis Cache
参考文章地址:https://dotnetcoretutorials.com/2017/01/06/using-redis-cache-net-core/ 具体步骤: 1 Install-Pack ...