Compatibility (Tensorflow, Python version, Compiler, Build tools, cuDNN and CUDA)
- see List
- Check the CUDA version (paths might differ slightly depending on the cuda version):
cat /usr/local/cuda/version.txt
- and cuDNN version:
grep CUDNN_MAJOR -A 2 /usr/local/cuda/include/cudnn.h
Check GPUs
Tensorflow 2
tf.config.list_physical_devices('GPU')
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
Porting (Tensorflow 1 to Tensorflow 2)
General
GraphDef
Error: module 'tensorflow' has no attribute 'GraphDef'
- source
- Yeah, the syntax has changed in T2.0. Here’s the correct piece:
tf.compat.v1.GraphDef() # -> instead of tf.GraphDef()
tf.compat.v2.io.gfile.GFile() # -> instead of tf.gfile.GFile()
Session
tf.compat.v1.Session()
instead oftf.Session()
Tensorboard
tensorboard --logdir=dir_with_eventfiles
in bash terminal- this will start the tensorboard server and then tensorboard can be viewed e.g. in firefox
tfrecords
Inspecting the first image in a tfrecords file
import tensorflow as tf
raw_dataset = tf.data.TFRecordDataset("path-to-file")
for raw_record in raw_dataset.take(1):
example = tf.train.Example()
example.ParseFromString(raw_record.numpy())
print(example)
- this also shows the other key-value pairs such as labels, bounding box coordinates, etc.
Memory Formats
NCHW
- data format for activations
- “NCHW” also describes the order in which the tensor values are laid out in memory
- source:
- NCHW stands for: batch N, channels C, depth D, height H, width W
- It is a way to store multidimensional arrays / data frames / matrix into memory, which can be considered as a 1-D array.
NHWC
Tensorflow API
tf.where
segmentation_map = tf.where(
condition=tf.reduce_all(tf.equal(image, color), axis=-1),
x=tf.cast(class_id, tf.uint8),
y=segmentation_map
)
Achtung: Reihenfolge von image
und color
bei tf.equal()
ist wichtig !