Tensorflow和pytorch安装(windows安装)

一、 Tensorflow安装

1、 Tensorflow介绍

 Tensorflow是广泛使用的实现机器学习以及其它涉及大量数学运算的算法库之一。Tensorflow由Google开发,是GitHub上最受欢迎的机器学习库之一。Google几乎在所有应用程序中都使用Tensorflow来实现机器学习。 例如,如果您使用到了Google照片或Google语音搜索,那么您就间接使用了Tensorflow模型。它们在大型Google硬件集群上工作,在感知任务方面功能强大。

2、Tensorflow安装(cpu版本)

我的环境是Anaconda3.5.2m,安装的是旧版本的tensorflow

pip install tensorflow==1.8.0

3、新版本安装

pip install tensorflow
pip install -U --ignore-installed wrapt enum34 simplejson netaddr
pip install tensorflow

4、验证代码

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

5、警告Your CPU supports instructions that this TensorFlow binar......处理

#忽略警告处理方法
import os 
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' 

6、GPU版本安装(GPU的没有环境,我没试验过)

#GPU版本还需要安装CUDA(N卡的)

pip install tensorflow-gpu

二、pytorch安装

pytorch官网:https://pytorch.org/

1、pytorch介绍

pytorch是一个python优先的深度学习框架,是一个和tensorflow,Caffe,MXnet一样,非常底层的框架。 

Torch 自称为神经网络界的 Numpy, 因为他能将 torch 产生的 tensor 放在 GPU 中加速运算 (前提是你有合适的 GPU), 就像 Numpy 会把 array 放在 CPU 中加速运算. 所以神经网络的话, 当然是用 Torch 的 tensor 形式数据最好。 就像 Tensorflow 当中的 tensor 一样。pytorch是一个动态的建图的工具。不像Tensorflow那样,先建图,然后通过feed和run重复执行建好的图。相对来说,pytorch具有更好的灵活性。

2、安装

打开 pytorch官网 ,然后根据情况选择安装的版本。

 我的python版本是3.6.5

pip install https://download.pytorch.org/whl/cpu/torch-1.1.0-cp36-cp36m-win_amd64.whl
pip  install https://download.pytorch.org/whl/cpu/torchvision-0.3.0-cp36-cp36m-win_amd64.whl

3、验证代码

import torch
print(torch.__version__)

猜你喜欢

转载自www.cnblogs.com/zhangb8042/p/11212319.html