LoginSignup
1
0

More than 3 years have passed since last update.

MacにKerasを導入する際に気をつけるべきこと

Last updated at Posted at 2020-01-02

はじめに

MacにKeras(tensorflow)導入時に,色々と突っ掛かったので,その備忘録としてまとめました.

環境

Mac OSX Mojave(10.14.6)
Python3.7.3

tensorflowとkerasのインストール

以下のコマンドをターミナルで実行.pipのバージョンが古いとうまく機能しないので,先にpipのバージョンを上げておく必要があります

pip install --upgrade pip
pip3 install --upgrade tensorflow
pip3 install keras

上記のあと,実際にpython3を立ち上げて動作を確認してみます.

Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> import keras
Using TensorFlow backend.
>>> 

無事導入ができました.

mnist.load_data()がうまくいかない

import keras
from keras.datasets import mnist
(train_images, train_labels), (test_images, test_labels) = 
mnist.load_data()

などと言う表記でおなじみのmnistですが,python3でmnist.load_data()を行うと,以下(省略表記ですが)

Exception: URL fetch failure on https://s3.amazonaws.com/img-
datasets/mnist.npz : None -- [SSL: CERTIFICATE_VERIFY_FAILED] 
certificate verify failed: unable to get local issuer certificate 
(_ssl.c:1056)

とのエラーが出る.これはcifar10.load_data()なんかでも同様です.こちらを参照に解決しました.
原因は

macOSに標準でインストールされているOpenSSLが古すぎるため、Python 3.6以降ではmacOS用のインストーラーにはOpenSSLが同梱され、システムのOpenSSLは参照されなくなりました

とのこと.
以下のコードをターミナルで実行することでcertifiモジュールをダウンロードしそこに含まれるルート証明書を参照可能になります.

cd /Applications/Python\ 3.7/Install\ Certificates.command

今後

Pythonでの深層学習については,こちらのまとめを参考にさせてただきました.
また問題が発生したら随時更新していきます.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0