from pathlib import Path from PIL import Image, ImageOps import matplotlib.pyplot as plt import numpy as np for path in Path("testowe").rglob("*.png"): image = Image.open(path).convert('L') image = ImageOps.invert(image) image = image.resize((28,28)) image = np.array(image).reshape(1, 28, 28, 1) / 255.0 plt.imshow(image.reshape(28,28), cmap='gray') plt.title("Przetworzony obraz") plt.axis("off") plt.show() prediction = model.predict(image)[0] predicted_digit = np.argmax(prediction) print(f"Rozpoznana cyfra: {predicted_digit}") print("\n---- Sprawdzenie 10 grafik z wyciętego zbioru testowego ----") for i, image in enumerate(images_to__check): image_input = image.reshape(1, 28, 28, 1) prediction = model.predict(image_input)[0] predicted_digit = np.argmax(prediction) true_label = np.argmax(labels_to_check[i]) plt.imshow(image.reshape(28, 28), cmap='gray') plt.title("Obra z MNIST") plt.axis("off") plt.show() print(f"Rozpoznana cyfra: {predicted_digit}")