TensorFlow: Difference between revisions

 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:


==Install==
==Install==
* Install CUDA and CuDNN
* Create a conda environment with python 3.5+
** <code>conda create -n my_env python=3.8</code>
* Install with pip


===Install TF2===
===Install TF2===
Easiest way is to install using conda to get a compatible tensorflow, cuda, and cudnn installed together.
See https://www.tensorflow.org/install/pip
Install tensorflow and [https://www.tensorflow.org/addons/overview tensorflow-addons]
Install tensorflow and [https://www.tensorflow.org/addons/overview tensorflow-addons]
<pre>
<pre>
conda install tensorflow-gpu
pip install tensorflow-addons
pip install tensorflow-addons
</pre>
</pre>
Line 23: Line 18:


===Install TF1===
===Install TF1===
The last official version of TensorFlow v1 is 1.15. This version does not work on RTX 3000+ (Ampere) GPUs. Your code will run but output bad results.<br>
If you need TensorFlow v1, see [https://github.com/NVIDIA/tensorflow nvidia-tensorflow].
<pre>
<pre>
conda install tensorflow-gpu=1.15
pip install nvidia-pyindex
pip install nvidia-tensorflow
</pre>
</pre>
;Notes
* Conda will automatically install a compatible cuda and cudnn into the cuda environment. Your host OS only needs to have a sufficiently new version of nvidia drivers installed.
* Sometimes, I get <code>CUDNN_STATUS_INTERNAL_ERROR</code>. This is fixed by setting the environment variable <code>TF_FORCE_GPU_ALLOW_GROWTH=true</code> in my conda env. See [https://stackoverflow.com/questions/46826497/conda-set-ld-library-path-for-env-only Add env variables to conda env]


==Usage (TF2)==
==Usage (TF2)==
Line 35: Line 29:
This is using the Keras API in tensorflow.keras.
This is using the Keras API in tensorflow.keras.
===Keras Pipeline===
===Keras Pipeline===
[https://www.tensorflow.org/api_docs/python/tf/keras/Model tf.keras.Model]
The general pipeline using Keras is:
The general pipeline using Keras is:
* Define a model, typically using [https://www.tensorflow.org/api_docs/python/tf/keras/Sequential tf.keras.Sequential]
* Define a model, typically using [https://www.tensorflow.org/api_docs/python/tf/keras/Sequential tf.keras.Sequential]