Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Tải và hiển thị ảnh bằng Keras

Để tải ảnh và hiển thị bằng thư viện Keras, dùng image.load_img() với target_size rồi gọi .show() trên đối tượng PIL Image.

Các bước

  • Import: from keras.preprocessing import image.
  • Tải ảnh: img = image.load_img('bird.jpg', target_size=(350, 750)).
  • Hiển thị: img.show() (mở viewer ảnh mặc định).

Ví dụ

from keras.preprocessing import image
img = image.load_img('bird.jpg', target_size=(350, 750))
img.show()

Kết quả

Tải và hiển thị ảnh bằng Keras