Removing Kernels
$ cd ~/Library/Jupyter/kernels
$ rm -r tensorflow_gpu/
See my post on:
Installing Jupyter kernels to match Conda environments
http://ukitech.blogspot.com/2017/02/kernel.html
In this blog, I take notes as I learn new skills for Android, Java, Python, Linux, SBC, Mac, Machine Learning and AI.
$ cd ~/Library/Jupyter/kernels
$ rm -r tensorflow_gpu/
$ pip install flask-ask
$ jupyter notebook
$ python skill_001.py * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger pin code: 275-052-815
$ /Applications/ngrok http 5000
ngrok by @inconshreveable (Ctrl+C to quit) Session Status online Version 2.1.18 Region United States (us) Web Interface http://127.0.0.1:4040 Forwarding http://908cd95a.ngrok.io -> localhost:5000 Forwarding https://908cd95a.ngrok.io -> localhost:5000 Connections ttl opn rt1 rt5 p50 p90 0 0 0.00 0.00 0.00 0.00
$ conda env create --file .../conda_environment.yml
$ conda info --envs
$ source activate py352_tf_gpu
$ python -m ipykernel install --user --name py352_tf_gpu --display-name "conda env py352_tf_gpu"$ jupyter notebook
$ echo $DYLD_LIBRARY_PATH/usr/local/cuda/lib:
$ echo $CUDA_HOME/Developer/NVIDIA/CUDA-8.0/
$ sudo easy_install pip
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl
$ echo $TF_BINARY_URL https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl
$ sudo pip3 install --upgrade $TF_BINARY_URL Password:The directory '/Users/ukilucas/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.The directory '/Users/ukilucas/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.Collecting tensorflow-gpu==1.0.0 from https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl Downloading https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl (89.0MB) 100% |████████████████████████████████| 89.0MB 8.8kB/s Requirement already up-to-date: numpy>=1.11.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Requirement already up-to-date: wheel>=0.26 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Requirement already up-to-date: six>=1.10.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Requirement already up-to-date: protobuf>=3.1.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Collecting setuptools (from protobuf>=3.1.0->tensorflow-gpu==1.0.0) Downloading setuptools-34.2.0-py2.py3-none-any.whl (389kB) 100% |████████████████████████████████| 399kB 2.0MB/s Requirement already up-to-date: appdirs>=1.4.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu==1.0.0)Requirement already up-to-date: packaging>=16.8 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu==1.0.0)Requirement already up-to-date: pyparsing in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from packaging>=16.8->setuptools->protobuf>=3.1.0->tensorflow-gpu==1.0.0)Installing collected packages: tensorflow-gpu, setuptools Found existing installation: tensorflow-gpu 0.12.1 Uninstalling tensorflow-gpu-0.12.1: Successfully uninstalled tensorflow-gpu-0.12.1 Found existing installation: setuptools 34.1.1 Uninstalling setuptools-34.1.1: Successfully uninstalled setuptools-34.1.1Successfully installed setuptools-34.2.0 tensorflow-gpu-1.0.0(tensorflow_gpu) uki@UkiPEsMcBookPro 192.168.1.24 19:44 dev $
(tensorflow_gpu) $ jupyter notebook
import tensorflow as tf
import time
from tensorflow.python.client import device_lib
def get_available_CPU_GPU():
devices = device_lib.list_local_devices()
#return [x.name for x in devices if x.device_type == 'CPU']
return [x.name for x in devices ]
print(get_available_CPU_GPU())
['/cpu:0', '/gpu:0']
start = timeit.timeit()
print ("starting")with tf.device('/gpu:0'):
# [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print (sess.run(c))
end = timeit.timeit()
print ("elapsed", end - start)starting
[[ 22. 28.]
[ 49. 64.]]
elapsed -0.003607149003073573
import PIL
import numpy
from PIL import Image
def resize_image(numpy_array_image, new_height):
# convert nympy array image to PIL.Image
image = Image.fromarray(numpy.uint8(numpy_array_image))
old_width = float(image.size[0])
old_height = float(image.size[1])
ratio = float( new_height / old_height)
new_width = int(old_width * ratio)
image = image.resize((new_width, new_height), PIL.Image.ANTIALIAS)
# convert PIL.Image into nympy array back again
return array(image)
$ conda create --name tensorflow_cpu --clone tensorflow_gpu
$ conda info --envs
# conda environments:
#
tensorflow * /Users/ukilucas/anaconda3/envs/tensorflow
tensorflow_cpu /Users/ukilucas/anaconda3/envs/tensorflow_cpu
tensorflow_gpu /Users/ukilucas/anaconda3/envs/tensorflow_gpu
root /Users/ukilucas/anaconda3
$ source activate tensorflow_cpuRegister this enviroment with Jupyter Notebook
$ source activate tensorflow
$ sudo pip install ipykernel
$ python -m ipykernel install --user --name tensorflow --display-name "conda env tensorflow"
import tensorflow as tf
print("OUT: tensorflow imported")
from tensorflow.python.client import device_lib
def get_available_CPU_GPU():
devices = device_lib.list_local_devices()
#return [x.name for x in devices if x.device_type == 'CPU']
return [x.name for x in devices ]
print(get_available_CPU_GPU())
print(get_available_CPU_GPU())
--------------------------------------------------------------------------- ImportError Traceback (most recent call last)in () ----> 1 from tensorflow.python.client import device_lib 2 3 def get_available_CPU_GPU(): 4 devices = device_lib.list_local_devices() 5 #return [x.name for x in devices if x.device_type == 'CPU'] ImportError: No module named 'tensorflow.python'
ImportError: No module named 'sklearn.model_selection'
(tensorflow_gpu) $ conda list | grep scikit
$ conda install scikit-learn
Fetching package metadata .........
Solving package specifications: .
Package plan for installation in environment /Users/ukilucas/anaconda3/envs/tensorflow_gpu:
The following NEW packages will be INSTALLED:
mkl: 2017.0.1-0 numpy: 1.11.3-py35_0 scikit-learn: 0.18.1-np111py35_1 scipy: 0.18.1-np111py35_1
(tensorflow_gpu) $ conda list | grep scikit
scikit-learn 0.18.1 np111py35_1
import sklearn0.18.1
print (sklearn.__version__)
from sklearn.model_selection import train_test_split
import sklearn
print (sklearn.__version__)
0.17.1
$ conda install scikit-learn
$ source activate tensorflow
$ conda install scikit-learn
(tensorflow) uki@Uki ~ $ jupyter notebook ~/dev/
$ conda listscikit-learn 0.18.1
sklearn 0.0
(py35) ~ $ conda remove scikit-learn
(py35) ~ $ pip uninstall scikit-learn
(py35) ~ $ pip uninstall sklearn
(py35) ~ $ conda install scikit-learn
(py35) ~ $ jupyter notebook ~/dev/
'/Users/ukilucas/anaconda3/bin/python'
$ conda list# packages in environment at /Users/ukilucas/anaconda3/envs/py35:
Deleting Old and Reinstalling Jupyter Notebook
from jupyter_core.paths import jupyter_data_dirprint(jupyter_data_dir())
/Users/ukilucas/Library/Jupyter
Deleting :
- /Users/ukilucas/Library/Jupyter
- ~/.ipython
- ~/.jupyter
$ rm -r ~/Library/Jupyter
$ rm -r ~/.ipython
$ rm -r ~/.jupyter
$ rm -r ~/anaconda3/
Downloads $ wget https://repo.continuum.io/archive/Anaconda3-4.3.0-MacOSX-x86_64.sh
bash Anaconda3-4.3.0-MacOSX-x86_64.sh
TensorFlow Installation instructions
# Python 3.5
$ conda create -n tensorflow python=3.5
# Mac OS X, GPU enabled, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py3-none-any.whl
$ sudo pip3 install --ignore-installed --upgrade $TF_BINARY_URL