What is the difference between tf.keras and tf.python.keras?

From an official TensorFlow dev, shortened (emphasis mine): The API import is in the root of the package. Any other import is just Python allowing you to access privates with no consideration for good coding practices. The only way that imports should be are import tensorflow as tf tf.keras We also provide support for from … Read more

Tensorflow 2.0 – AttributeError: module ‘tensorflow’ has no attribute ‘Session’

According to TF 1:1 Symbols Map, in TF 2.0 you should use tf.compat.v1.Session() instead of tf.Session() https://docs.google.com/spreadsheets/d/1FLFJLzg7WNP6JHODX5q8BDgptKafq_slHpnHVbJIteQ/edit#gid=0 To get TF 1.x like behaviour in TF 2.0 one can run import tensorflow.compat.v1 as tf tf.disable_v2_behavior() but then one cannot benefit of many improvements made in TF 2.0. For more details please refer to the migration guide … Read more

Why is TensorFlow 2 much slower than TensorFlow 1?

UPDATE 8/1730/2020: TF 2.3 has finally done it: all cases run as fast, or notably faster, than any previous version. Further, my previous update was unfair to TF; my GPU was to blame, has been overheating lately. If you see a rising stem plot of iteration times, it’s a reliable symptom. Lastly, see a dev’s … Read more

Could not load dynamic library ‘cudart64_101.dll’ on tensorflow CPU-only installation

Tensorflow 2.1+ What’s going on? With the new Tensorflow 2.1 release, the default tensorflow pip package contains both CPU and GPU versions of TF. In previous TF versions, not finding the CUDA libraries would emit an error and raise an exception, while now the library dynamically searches for the correct CUDA version and, if it … Read more

Keras not training on entire dataset

The number 1875 shown during fitting the model is not the training samples; it is the number of batches. model.fit includes an optional argument batch_size, which, according to the documentation: If unspecified, batch_size will default to 32. So, what happens here is – you fit with the default batch size of 32 (since you have … Read more

How to prevent tensorflow from allocating the totality of a GPU memory?

You can set the fraction of GPU memory to be allocated when you construct a tf.Session by passing a tf.GPUOptions as part of the optional config argument: # Assume that you have 12GB of GPU memory and want to allocate ~4GB: gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333) sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) The per_process_gpu_memory_fraction acts as a hard upper bound … Read more