# tf.keras.utils.load_img

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v2.13.1/keras/utils/image_utils.py#L364-L480) |

Loads an image into PIL format.

#### View aliases


**Main aliases**

[`tf.keras.preprocessing.image.load_img`](https://www.tensorflow.org/api_docs/python/tf/keras/utils/load_img)
**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

\`tf.compat.v1.keras.preprocessing.image.load_img\`, \`tf.compat.v1.keras.utils.load_img\`

<br />

    tf.keras.utils.load_img(
        path,
        grayscale=False,
        color_mode='rgb',
        target_size=None,
        interpolation='nearest',
        keep_aspect_ratio=False
    )

#### Usage:

    image = tf.keras.utils.load_img(image_path)
    input_arr = tf.keras.utils.img_to_array(image)
    input_arr = np.array([input_arr])  # Convert single image to a batch.
    predictions = model.predict(input_arr)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `path` | Path to image file. |
| `grayscale` | DEPRECATED use `color_mode="grayscale"`. |
| `color_mode` | One of `"grayscale"`, `"rgb"`, `"rgba"`. Default: `"rgb"`. The desired image format. |
| `target_size` | Either `None` (default to original size) or tuple of ints `(img_height, img_width)`. |
| `interpolation` | Interpolation method used to resample the image if the target size is different from that of the loaded image. Supported methods are `"nearest"`, `"bilinear"`, and `"bicubic"`. If PIL version 1.1.3 or newer is installed, `"lanczos"` is also supported. If PIL version 3.4.0 or newer is installed, `"box"` and `"hamming"` are also supported. By default, `"nearest"` is used. |
| `keep_aspect_ratio` | Boolean, whether to resize images to a target size without aspect ratio distortion. The image is cropped in the center with target aspect ratio before resizing. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A PIL Image instance. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ImportError` | if PIL is not available. |
| `ValueError` | if interpolation method is not supported. |

<br />