pythontensorflowkerasresnetimagenet

How to understand TensorFlow source code for Imagenet preprocessing


I want to understand and replicate how does tensorflow.keras do the preprocessing of imagenet in the function tf.keras.applications.resnet.preprocess_input, but I can not understand the source code:

@keras_export('keras.applications.imagenet_utils.preprocess_input')
@keras_modules_injection
def preprocess_input(*args, **kwargs):
  return imagenet_utils.preprocess_input(*args, **kwargs)

The definition seems to be recursive. Moreover, the documentation does not say anything about the function. How can I see what is this function really doing?


Solution

  • I think this link will help. https://github.com/keras-team/keras-applications/blob/master/keras_applications/imagenet_utils.py. The definition is actually not recursive because the import statement from keras_applications import imagenet_utils will allow you to use the preprocess_input function from the imagenet_utils located in keras rather than calling itself.