Keras 3 API documentation / Keras Applications / Xception / Xception preprocessing utilities

Xception preprocessing utilities

[source]

decode_predictions function

keras.applications.xception.decode_predictions(preds, top=5)

Decodes the prediction of an ImageNet model.

Arguments

  • preds: NumPy array encoding a batch of predictions.
  • top: Integer, how many top-guesses to return. Defaults to 5.

Returns

A list of lists of top class prediction tuples (class_name, class_description, score). One list of tuples per sample in batch input.

Raises

  • ValueError: In case of invalid shape of the pred array (must be 2D).

Guides and examples using decode_predictions


[source]

preprocess_input function

keras.applications.xception.preprocess_input(x, data_format=None)

Preprocesses a tensor or Numpy array encoding a batch of images.

Usage example with applications.MobileNet:

i = keras.layers.Input([None, None, 3], dtype="uint8")
x = ops.cast(i, "float32")
x = keras.applications.mobilenet.preprocess_input(x)
core = keras.applications.MobileNet()
x = core(x)
model = keras.Model(inputs=[i], outputs=[x])
result = model(image)

Arguments

  • x: A floating point numpy.array or a backend-native tensor, 3D or 4D with 3 color channels, with values in the range [0, 255]. The preprocessed data are written over the input data if the data types are compatible. To avoid this behaviour, numpy.copy(x) can be used.
  • data_format: Optional data format of the image tensor/array. None, means the global setting keras.backend.image_data_format() is used (unless you changed it, it uses "channels_last"). Defaults to None.

Returns

Preprocessed array with type float32.

The inputs pixel values are scaled between -1 and 1, sample-wise.

Raises

  • ValueError: In case of unknown data_format argument.

Guides and examples using preprocess_input