Skip to content

MacOS上安装TensorFlow和Keras并用与深度学习 #31

Description

@zibuyu1995

在本教程中你将学习如何在macos上搭建深度学习平台

Mac 环境配置

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • homebrew 加速(可选)

自备小火箭

export ALL_PROXY=socks5://127.0.0.1:1080
  • Python 3.6 安装

官网下载3.6.5包

基本依赖安装

brew install cmake pkg-config wget
brew install jpeg libpng libtiff openexr
brew install eigen tbb hdf5

Python虚拟环境安装

可以选择pipenv(虽然我很讨厌这个包),也可以采用virtualenvwrapper
这里选用virtualenvwrapper

  • 安装 virtualenv virtualenvwrapper
pip3 install virtualenv virtualenvwrapper
  • 用virtualenvwrapper管理虚拟环境
$ vi ~/.profile 或者 vi ~/.zshrc

# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

$ source ~/.zshrc
  • 创建虚拟环境
 mkvirtualenv DeepLearning

image

激活虚拟环境

workon DeepLearning 

安装OpenCv IPython

  • OpenCv 安装
pip install opencv-contrib-python -i https://pypi.douban.com/simple/

image

  • 安装ipython
pip install ipython -i https://pypi.douban.com/simple/

安装TensorFlow和Keras

  • 基本视觉库安装
pip install scipy pillow -i https://pypi.douban.com/simple/
pip install imutils h5py requests progressbar2 -i https://pypi.douban.com/simple/
pip install scikit-learn scikit-image  -i https://pypi.douban.com/simple/
pip install matplotlib -i https://pypi.douban.com/simple/
mkdir ~/.matplotlib
touch ~/.matplotlib/matplotlibrc
echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc
  • 安装TensorFlow和Keras
pip install tensorflow -i https://pypi.douban.com/simple/
pip install keras -i https://pypi.douban.com/simple/
  • 验证
    image
    image

Demo运行

计算张量积(在tensorflow程序中所有的数据都通过张量的形式来表示)

import tensorflow as tf


x1 = tf.constant([1,2,3,4])
x2 = tf.constant([5,6,7,8])
result = tf.multiply(x1, x2)

with tf.Session() as s:
    print(s.run(result))

# out: [ 5 12 21 32]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions