tf.keras.utils.load_img
Stay organized with collections
Save and categorize content based on your preferences.
Loads an image into PIL format.
tf.keras.utils.load_img(
path,
color_mode='rgb',
target_size=None,
interpolation='nearest',
keep_aspect_ratio=False
)
Used in the notebooks
Used in the guide |
Used in the tutorials |
|
|
Example:
image = keras.utils.load_img(image_path)
input_arr = keras.utils.img_to_array(image)
input_arr = np.array([input_arr]) # Convert single image to a batch.
predictions = model.predict(input_arr)
Args |
path
|
Path to image file.
|
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.
|
Returns |
A PIL Image instance.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-07 UTC."],[],[]]