Why is there no documentation for keras.engine?

Viewed 86

I am trying to use https://github.com/matterport/Mask_RCNN, but get the error AttributeError: module 'keras.engine' has no attribute 'Layer'.

I'm not the only one who's had this problem - here are some suggestions for how to solve it.

Now, trying to better understand the problem, I have searched for documentation of the keras.engine module, but have found nothing. In the official Keras API reference, there seems to be no mentioning of anything called 'engine'. Why is this the case? How is one supposed to use a module for which there is no documentation?

1 Answers

TLDR

No one** is supposed to use the keras.engine module because it is not part of the public API.

Explanation

In most projects (e.g. Keras) the assumption is that you shouldn't rely on features that are not documented because they can change at any time. I think that's exactly what happened here. As Dr. Snooppy pointed out in the comments, Matterport shouldn't have called keras.engine.Layer for precisely this reason.

Finding docs and source

Keras is open source and keras.engine is full of docstrings, so if you really want to get to the source of something it's not that hard:

  • Find the site-packages folder with python -m site
  • Navigate to .../site-packages/tensorflow/keras/python/engine
  • Check out the source files. Pay particular attention to the class keywords and to class and method docstrings (These are delimited by """).
  • In my Tensorflow/Keras version 2.6.0, a file search yields that class Layer is now in a different place than the two mentioned in the linked answer: .../site-packages/tensorflow/keras/python/engine/base_layer.py, illustrating the point that anything that's not part of the public API may and does change all the time.

** Obvious exception: the engineers who write code for the Keras library.

Related