[PYTHON] Things to keep in mind when deploying Keras on your Mac

Introduction

When I introduced Keras (tensorflow) to my Mac, I ran into various things, so I summarized it as a memorandum.

environment

Mac OSX Mojave(10.14.6) Python3.7.3

Install tensorflow and keras

Execute the following command in the terminal. If the version of pip is old, it will not work well, so you need to upgrade the version of pip first **

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

After the above, actually launch python3 and check the operation.

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.
>>> 

I was able to install it safely.

mnist.load_data () doesn't work

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

It is a familiar mnist with the notation such as, but if you do mnist.load_data () with python3, the following (although it is abbreviated notation)

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)

I get an error. This is the same for cifar10.load_data (). Solved by referring to here. The cause is

OpenSSL installed by default on macOS is too old, so since Python 3.6, the installer for macOS includes OpenSSL and the system's OpenSSL is no longer referenced.

And that. You can download the certifi module by executing the following code in the terminal and refer to the root certificate included in it.

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

from now on

For deep learning in Python, I referred to the summary of here. In addition, we will update it as needed when problems occur.

Recommended Posts

Things to keep in mind when deploying Keras on your Mac
Things to keep in mind when developing crawlers in Python
Things to keep in mind when copying Python lists
Things to keep in mind when processing strings in Python2
Things to keep in mind when processing strings in Python3
Things to keep in mind when doing Batch Prediction on GCP ML Engine
Things to keep in mind when using Python with AtCoder
Things to keep in mind when using cgi with python.
Things to keep in mind when converting row vectors to column vectors with ndarray
Things to keep in mind when using Python for those who use MATLAB
Things to keep in mind when building automation tools for the manufacturing floor in Python
Summary of points to keep in mind when writing a program that runs on Python 2.5
Things to watch out for when creating a Python environment on a Mac
Steps to install the latest Python on your Mac
A memorandum on how to use keras.preprocessing.image in Keras
Things to note when initializing a list in Python
How to exit when using Python in Terminal (Mac)
How to delete "(base)" that appears in the terminal when Anaconda is installed on Mac
Install numba on your Mac
Update python on Mac to 3.7-> 3.8
Install Django on your Mac
Things to watch out for when using default arguments in Python
Things to watch out for when naming dynamic routing in nuxt.js
Things to note when running Python on EC2 from AWS Lambda
Try to log in to Netflix automatically using python on your PC
Steps to install matplotlib on Mac
Convert wma to mp3 on Mac
How to install OpenCV on Mac
Steps to install python3 on mac
Update Python on Mac from 2 to 3
How to use gcc when compiling extension modules from setup.py on Mac
How to read environment variables from .env file in PyCharm (on Mac)