[Solved] TensorFlow – tf.layers vs tf.contrib.layers

In TensorFlow, tf.layers and tf.contrib.layers share a lot of functionality (standard 2D convolutional layers, batch normalization layers, etc). Is the difference between these two just that the contrib.layers package is still experimental where the layers package is considered stable? Or is one being replaced by the other? Other differences? Why are these two separate?

Solution #1:

You’ve answered your own question. The description on the official documentation for the tf.contrib namespace is:

contrib module containing volatile or experimental code.

So tf.contrib is reserved for experimental features. APIs in this namespace are allowed to change rapidly between versions, whereas the others usually can’t without a new major version.

In particular, the functions in tf.contrib.layers are not identical to those found in tf.layers, although some of them might be replicated with different names.

As for whether you should use them, that depends on whether you are willing to handle sudden breaking changes. Code that doesn’t rely on tf.contrib may be easier to migrate to future versions of TensorFlow.

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.