A guide to install and make work an already compiled version of Tensorflow 1.8 - GPU on MacOS 10.13.6.
PREREQUISITE: Having an Nvidia GPU or EGPU (already working)
(note: follow the guide at your own risk.
note2: Big part of this guide is taken from this other guide):
1. Install Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install wget
2. Install Nvidia Web Drivers:
https://images.nvidia.com/mac/pkg/387/WebDriver-387.10.10.10.40.105.pkg
3. Install Nvidia Cuda Drivers:
https://www.nvidia.com/object/macosx-cuda-387.178-driver.html
4. Download Xcode 8.2.xip and Xcode 9.4.xip, extract both .app files, rename them to Xcode8.2.app and Xcode9.4 respectively and move then to Applications folder:
You need to search for them there, they're about 4.2GB and 5.2GB. V9.4 will be needed to install OpenMP, which suggests to install that version. I don't know if latest Xcode version works instead of 9.4, if you already have latest, you could try to use that. V8.2 is essential, anyway.
5. Set Xcode8.2 as default:
sudo xcode-select -s /Applications/Xcode8.2.app
6. Install bazel:
brew install bazel
7. Install cuda 9.1.128:
8. Download and install nccl 1.3.4:
https://storage.googleapis.com/74thopen/tensorflow_osx/nccl_osx_1.3.4.tar.gz
unarchive it, open a terminal window into the extracted folder and move it into /usr/local/nccl by performing:
sudo mkdir -p /usr/local/nccl
cd nccl_2.1.15-1+cuda9.1_x86_64
sudo mv * /usr/local/nccl
sudo mkdir -p /usr/local/include/third_party/nccl
sudo ln -s /usr/local/nccl/include/nccl.h /usr/local/include/third_party/nccl
9. Edit ~/.bash_profile by inserting:
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/cuda/extras/CUPTI/lib
export LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
export PATH=$DYLD_LIBRARY_PATH:$PATH:/Developer/NVIDIA/CUDA-9.1/bin
in it.
10. Compile CUDA samples to test if GPU is working correctly:
cd /Developer/NVIDIA/CUDA-9.1/samples
chown -R $(whoami) *
make -C 1_Utilities/deviceQuery
./bin/x86_64/darwin/release/deviceQuery
You should get this result at the bottom of the terminal:
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.1, CUDA Runtime Version = 9.1, NumDevs = 1Result = PASS
11. Register here and download cuDNN 7.0.5:
Perform:
tar -xzvf cudnn-9.1-osx-x64-v7-ga.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib/libcudnn* /usr/local/cuda/lib
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib/libcudnn*
to extract and copy required files into CUDA install folder.
12. Download and install Python 3.6.4:
https://www.python.org/ftp/python/3.6.4/python-3.6.4-macosx10.6.pkg
Now this is where i stopped following the guide.
13. Install Tensorflow 1.8 (other versions HERE):
pip3 install https://storage.googleapis.com/74thopen/tensorflow_osx/tensorflow-1.8.0-cp36-cp36m-macosx_10_13_x86_64.whl
14. Set Xcode9.4 as default:
sudo xcode-select -s /Applications/Xcode9.4.app
15. Install OpenMP:
brew install cliutils/apple/libomp
16. Finally, test the whole installation: Run in terminal:
python
then
>>> import tensorflow as tf
>>> tf.Session()
you should get some messages about your GPU, memory and others (### i will insert the exact returned message ###).
17. If you get -ncclAllReduce issue:
- Download file here:
- Execute:
gcc -c -fPIC nccl_ops.cc -o hello_world.o
- Execute:
gcc hello_world.o -shared -o _nccl_ops.so
- Replace generated file "nccl_ops.so" at Path:
tensorflow/contrib/nccl/python/ops
To find where TF is installed:
pip3 show tensorflow
you will get:
Name: tensorflow
Version: 1.8.0
Summary: TensorFlow helps the tensors flow
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Requires: grpcio, tensorboard, wheel, astor, gast, protobuf, termcolor, numpy, six, absl-py
Required-by:
Then repeat step 16, if everything works, congratulations, you have tensorflow 1.8 with GPU support installed!
Moreover, if you want to test a sample code to be sure everything really works, then download and run
https://github.com/antoniopioricciardi/Tensorflow-MacOS-10.13.6-eGPU/blob/master/TFtest.py
Hi, I'm getting below error. I have no clue what is wrong and where. Please help.
Aagnyas-Air:Nails Aagnya$ python3 custom.py train --dataset=customImages --weights=coco
Using TensorFlow backend.
Weights: coco
Dataset: customImages
Logs: /Users/Aagnya/Documents/AppCodes/Applications/logs
Configurations:
BACKBONE resnet101
BACKBONE_STRIDES [4, 8, 16, 32, 64]
BATCH_SIZE 2
BBOX_STD_DEV [0.1 0.1 0.2 0.2]
COMPUTE_BACKBONE_SHAPE None
DETECTION_MAX_INSTANCES 100
DETECTION_MIN_CONFIDENCE 0.9
DETECTION_NMS_THRESHOLD 0.3
FPN_CLASSIF_FC_LAYERS_SIZE 1024
GPU_COUNT 1
GRADIENT_CLIP_NORM 5.0
IMAGES_PER_GPU 2
IMAGE_MAX_DIM 1024
IMAGE_META_SIZE 14
IMAGE_MIN_DIM 800
IMAGE_MIN_SCALE 0
IMAGE_RESIZE_MODE square
IMAGE_SHAPE [1024 1024 3]
LEARNING_MOMENTUM 0.9
LEARNING_RATE 0.001
LOSS_WEIGHTS {'rpn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_class_loss': 1.0, 'mrcnn_bbox_loss': 1.0, 'mrcnn_mask_loss': 1.0}
MASK_POOL_SIZE 14
MASK_SHAPE [28, 28]
MAX_GT_INSTANCES 100
MEAN_PIXEL [123.7 116.8 103.9]
MINI_MASK_SHAPE (56, 56)
NAME nail
NUM_CLASSES 2
POOL_SIZE 7
POST_NMS_ROIS_INFERENCE 1000
POST_NMS_ROIS_TRAINING 2000
ROI_POSITIVE_RATIO 0.33
RPN_ANCHOR_RATIOS [0.5, 1, 2]
RPN_ANCHOR_SCALES (32, 64, 128, 256, 512)
RPN_ANCHOR_STRIDE 1
RPN_BBOX_STD_DEV [0.1 0.1 0.2 0.2]
RPN_NMS_THRESHOLD 0.7
RPN_TRAIN_ANCHORS_PER_IMAGE 256
STEPS_PER_EPOCH 100
TOP_DOWN_PYRAMID_SIZE 256
TRAIN_BN False
TRAIN_ROIS_PER_IMAGE 200
USE_MINI_MASK True
USE_RPN_ROIS True
VALIDATION_STEPS 50
WEIGHT_DECAY 0.0001
Loading weights /Users/Aagnya/Documents/AppCodes/Applications/mask_rcnn_coco.h5
2019-01-06 22:25:18.813208: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:859] OS X does not support NUMA - returning NUMA node zero
2019-01-06 22:25:18.814461: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties:
name: GeForce GTX 1070 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.683
pciBusID: 0000:c3:00.0
totalMemory: 8.00GiB freeMemory: 7.24GiB
2019-01-06 22:25:18.814514: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0
2019-01-06 22:25:20.799216: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-01-06 22:25:20.799247: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0
2019-01-06 22:25:20.799256: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N
2019-01-06 22:25:20.801938: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6990 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070 Ti, pci bus id: 0000:c3:00.0, compute capability: 6.1)
2019-01-06 22:25:20.804368: E tensorflow/stream_executor/cuda/cuda_driver.cc:936] failed to allocate 6.83G (7329701632 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2019-01-06 22:25:22.579117: E tensorflow/core/grappler/clusters/utils.cc:127] Not found: TF GPU device with id 0 was not registered
2019-01-06 22:25:23.544083: E tensorflow/core/grappler/clusters/utils.cc:127] Not found: TF GPU device with id 0 was not registered
2019-01-06 22:25:25.234273: E tensorflow/core/grappler/clusters/utils.cc:127] Not found: TF GPU device with id 0 was not registered
Training network heads
Traceback (most recent call last):
File "custom.py", line 365, in
train(model)
File "custom.py", line 201, in train
layers='heads')
File "/Users/Aagnya/Documents/AppCodes/Applications/untitled folder/Nails/mrcnn/model.py", line 2348, in train
histogram_freq=0, write_graph=True, write_images=False),
File "/usr/local/lib/python3.6/site-packages/keras/callbacks.py", line 745, in init
from tensorflow.contrib.tensorboard.plugins import projector
File "/usr/local/lib/python3.6/site-packages/tensorflow/contrib/init.py", line 36, in
from tensorflow.contrib import distribute
File "/usr/local/lib/python3.6/site-packages/tensorflow/contrib/distribute/init.py", line 22, in
from tensorflow.contrib.distribute.python.cross_tower_ops import *
File "/usr/local/lib/python3.6/site-packages/tensorflow/contrib/distribute/python/cross_tower_ops.py", line 23, in
from tensorflow.contrib.distribute.python import cross_tower_utils
File "/usr/local/lib/python3.6/site-packages/tensorflow/contrib/distribute/python/cross_tower_utils.py", line 23, in
from tensorflow.contrib import nccl
File "/usr/local/lib/python3.6/site-packages/tensorflow/contrib/nccl/init.py", line 30, in
from tensorflow.contrib.nccl.python.ops.nccl_ops import all_max
File "/usr/local/lib/python3.6/site-packages/tensorflow/contrib/nccl/python/ops/nccl_ops.py", line 30, in
resource_loader.get_path_to_datafile('_nccl_ops.so'))
File "/usr/local/lib/python3.6/site-packages/tensorflow/contrib/util/loader.py", line 56, in load_op_library
ret = load_library.load_op_library(path)
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/load_library.py", line 56, in load_op_library
lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: dlopen(/usr/local/lib/python3.6/site-packages/tensorflow/contrib/nccl/python/ops/_nccl_ops.so, 6): Symbol not found: _ncclAllReduce
Referenced from: /usr/local/lib/python3.6/site-packages/tensorflow/contrib/nccl/python/ops/_nccl_ops.so
Expected in: flat namespace
in /usr/local/lib/python3.6/site-packages/tensorflow/contrib/nccl/python/ops/_nccl_ops.so
Aagnyas-Air:Nails Aagnya$