MATLAB: GoogleNet Memory Error

Deep Learning Toolbox

I am encountering an error about running out of memory when running the example from the following page on my Mac. It works fine for my Windows machine.  
https://www.mathworks.com/help/nnet/ref/googlenet.html
This seems to happen in the 'classify' function. Is there any way to prevent this error? 
Initializing image normalization. 
=======================================================================================================================
| Epoch | Iteration | Time Elapsed | Mini-batch | Validation | Mini-batch | Validation | Base Learning| 
| | | (seconds) | Loss | Loss | Accuracy | Accuracy | Rate | 
=======================================================================================================================
| 1 | 1 | 35.79 | 1.8003 | 1.5662 | 10.00% | 30.00% | 1.00e-04 | 
| 1 | 2 | 89.56 | 1.6208 | | 20.00% | | 1.00e-04 | 
| 1 | 3 | 120.45 | 1.5544 | 0.9864 | 20.00% | 70.00% | 1.00e-04 | 
| 1 | 4 | 177.26 | 1.1172 | | 70.00% | | 1.00e-04 | 
| 1 | 5 | 212.55 | 0.7896 | | 70.00% | | 1.00e-04 | 
| 2 | 6 | 246.57 | 0.3700 | 0.3806 | 100.00% | 95.00% | 1.00e-04 | 
| 2 | 7 | 297.17 | 0.5127 | | 80.00% | | 1.00e-04 | 
| 2 | 8 | 329.78 | 0.2577 | | 90.00% | | 1.00e-04 | 
| 2 | 9 | 361.55 | 0.1758 | 0.1747 | 90.00% | 95.00% | 1.00e-04 | 
| 2 | 10 | 410.42 | 0.1206 | | 100.00% | | 1.00e-04 | 
| 3 | 11 | 440.39 | 0.0503 | | 100.00% | | 1.00e-04 | 
| 3 | 12 | 470.37 | 0.1585 | 0.1263 | 90.00% | 95.00% | 1.00e-04 | 
| 3 | 13 | 516.70 | 0.0455 | | 100.00% | | 1.00e-04 | 
| 3 | 14 | 546.64 | 0.0374 | | 100.00% | | 1.00e-04 | 
| 3 | 15 | 577.32 | 0.0632 | 0.1116 | 100.00% | 95.00% | 1.00e-04 | 
=======================================================================================================================
Error using gpuArray/cat 
Out of memory on device. To view more detail about available memory on the GPU, use 'gpuDevice()'. If the problem persists, reset the GPU by calling 'gpuDevice(1)'. 
Error in nnet.internal.cnn.layer.Concatenation/predict (line 41) 
Z = cat(this.ConcatenationAxis, X{:}); 
Error in nnet.internal.cnn.DAGNetwork/forwardPropagationWithPredict (line 236) 
outputActivations = this.Layers{i}.predict(XForThisLayer); 
Error in nnet.internal.cnn.DAGNetwork/predict (line 317) 
activationsBuffer = this.forwardPropagationWithPredict(X); 
Error in DAGNetwork/predict (line 426) 
YBatch = this.PrivateNetwork.predict(X); 
Error in DAGNetwork/classify (line 490) 
scores = this.predict( X, varargin{:} ); 
Error in TransferLearningUsingGoogLeNetExample (line 83) 
predictedLabels = classify(net,valImages); 

Best Answer

The error is likely due to hardware differences and not based on the OS. This error might be due to limited memory on your GPU. Try setting the 'ExecutionEnvironment' to 'cpu' for the trainingOptions since the default will use the 'gpu' if one is available. 
https://www.mathworks.com/help/nnet/ref/trainingoptions.html#input_argument_namevalue_d119e53360