This assumes miniconda3 has been installed and is being used for environment and package management. See this gist for setup details.
Keras is a higher level library that uses various backends (e.g., Tensorflow, CLTK, ...).
We have setup a miniconda environment with the typical packages:
conda create -n keras python
source activate keras
conda install keras matplotlib
TensorFlow is Google's deep learning framework, which can be configured to run on CPUs, GPUs, or Google Cloud.
Vanilla install with Python, such as adding it to the keras
environment (created above):
source activate keras
conda install tensorflow
Alternatively, you can download a macOS-optimized build from https://github.com/lakshayg/tensorflow-build and install it:
source activate keras
pip install --ignore-installed --upgrade tensorflow-1.8.0-cp36-cp36m-macosx_10_7_x86_64.whl
NOTE: as of TensorFlow v1.6.0, all CPU optimizations are included in the build, which may not be available on your Mac. This will result in failures like: illegal instruction: 4.
Or, build it from source following this guide, which distills to:
brew install bazel coreutils
conda install six numpy wheel
git clone https://github.com/tensorflow/tensorflow
cd tensorflow
./configure
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
source activate keras
pip install /tmp/tensorflow_pkg/tensorflow-1.9.0rc0-cp36-cp36m-macosx_10_7_x86_64.whl
pip install keras
Have a lot of patience and work through NVIDIA driver updates, CUDA installs, and GPU-enabled Tensorflow build with this elaborate walkthrough.
Instead of the last few steps in the Ubuntu install, activate the keras
environment (created above) and install the whl
using pip
:
cd ~/tensorflow/tensorflow_pkg
source activate keras
pip install --ignore-installed --upgrade tensorflow-1.8.0-cp36-cp36m-linux_x86_64.whl
<html>
<head>
<!-- Load TensorFlow.js -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"> </script>
<!-- Place your code in the script tag below. You can also use an external .js file -->
<script>
// Notice there is no 'import' statement. 'tf' is available on the index-page
// because of the script tag above.
// Define a model for linear regression.
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));
// Prepare the model for training: Specify the loss and the optimizer.
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
// Generate some synthetic data for training.
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);
// Train the model using the data.
model.fit(xs, ys, {epochs: 10}).then(() => {
// Use the model to do inference on a data point the model hasn't seen before:
// Open the browser devtools to see the output
model.predict(tf.tensor2d([5], [1, 1])).print();
});
</script>
</head>
<body>
</body>
</html>
# base package
npm install @tensorflow/tfjs
# non-gpu version
npm install @tensorflow/tfjs-node
# gpu version
npm install @tensorflow/tfjs-node-gpu
To get all environments, it is best to install from the repo.
apt-get install -y python-numpy python-dev cmake zlib1g-dev libjpeg-dev xvfb ffmpeg xorg-dev python-opengl libboost-all-dev libsdl2-dev swig
brew install cmake boost boost-python sdl2 swig wget
git clone https://github.com/openai/gym.git
cd gym
source activate keras
pip install -e '.[all]'