基於mac的keras深度學習環境搭建

mac環境下使用keras進行深度學習開發,環境搭建記錄。

一、Python

mac系統默認帶python2.7,且不能輕易刪除,想要安裝python3,保留兩個python版本隨時切換使用,參見我的另一篇博客
記Mac 裝 python3 的過程,如何在多版本切換

二、TensorFlow

1 介紹

TensorFlow是一個採用數據流圖,用於數值計算的開源軟件庫。節點(Note)在圖中表示數學操作,線(Edge)表示節點間相互聯繫的多維數據數組,即張量(Tensor)。

2 安裝

TensorFlow可以支持Python2.7-3.6,但是我是在python3.7下安裝的,也能用,後續有問題再說。
安裝命令

pip3 install tensorflow

安裝過程
在這裏插入圖片描述
期間報錯1

matplotlib 1.3.1 requires nose, which is not installed.
matplotlib 1.3.1 requires tornado, which is not installed.

在這裏插入圖片描述
解決
只需要安裝nose 和tornado即可:

sudo easy_install nose

sudo easy_install tornado

參考:python中安裝matplotlib

報錯2

Cannot uninstall ‘numpy’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

在這裏插入圖片描述
解決
強行安裝更新更高的版本

sudo pip install numpy --ignore-installed numpy

參考:安裝theano時候發現報錯:cannot install '‘numpy’.It is a distutils installed project and thus we cannot …

3 驗證

import tensorflow

在這裏插入圖片描述

三、Keras

1 介紹

Keras是一個高層神經網絡API,Keras完全由Python編寫而成,使用TensorFlow、Theano及CNTK作爲後端。Keras是爲支持快速實驗而生,可以迅速將想發轉換爲結果。Keras適用的Python版本是:Python2.7-3.6,並能在CPU和GPU之間無縫切換。

2 安裝

Keras的安裝依賴SciPy環境,並且還需要先安裝CNTK或TensorFlow等後端。

安轉命令

pip3 install --user keras

注:現在mac電腦上有默認的python2.7和我自己安裝的python3.7,如果用命令>pip install --user keras,實在2.7的基礎上安裝,如下
在這裏插入圖片描述
此時python3環境導入keras 出錯
在這裏插入圖片描述

3 驗證

在這裏插入圖片描述
使用pip3 命令正確安裝keras後 驗證

import keras

在這裏插入圖片描述

四、Pycharm配置

pycharm—preferences—project—project interpreter—選右邊的設置按鈕
在這裏插入圖片描述

—選新的環境
在這裏插入圖片描述
—最終
在這裏插入圖片描述

參考:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章