12

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?

E_net4
  • 27,810
  • 13
  • 101
  • 139
golmschenk
  • 11,736
  • 20
  • 78
  • 137

1 Answers1

16

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.

E_net4
  • 27,810
  • 13
  • 101
  • 139
  • Is there any reason that much of the functionality is duplicated between these modules? Are the versions in tf.contrib.layers, say, experimental versions with better optimization or something? Or are they just leftover from before the layers module was added to tf for historical reasons? – erobertc Mar 09 '18 at 18:29
  • 1
    @erobert That may have to be evaluated on a case-by-case basis. Often, `tf.contrib` enables the community to experiment with different APIs and expose less stable features in the process. As such, they do not have to disappear immediately after a new feature lands. Likewise, they may also be completely changed or cleaned up on a minor release. At the moment, for example, `tf.layers.conv2d` and `tf.contrib.layers.conv2d` have different prototypes and are not always interchangeable. – E_net4 Mar 09 '18 at 18:47