# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# +
from tensorflow import keras
from sklearn.metrics import accuracy_score
import os
import pickle

def load_data():
    X_train = pickle.load(open("X_train.pickle", "rb"))
    X_test = pickle.load(open("X_test.pickle", "rb"))
    y_train = pickle.load(open("y_train.pickle", "rb"))
    y_test = pickle.load(open("y_test.pickle", "rb"))
    
    return X_train, X_test, y_train, y_test


X_train, X_test, y_train, y_test = load_data()
model = keras.models.load_model("model_save")


# -

def predictions(model, data):
    preds = []
    for each in model.predict(data):
        preds.append(1 if each > 0.5 else 0)
    return preds


# +
import cv2 as cv

testing_dir = "dataset/data/test"
testing_images = []

for image_name in os.listdir(testing_dir):
    image_path = os.path.join(testing_dir, image_name)
    image = cv.imread(image_path, 0) / 255.0
    image = cv.resize(image, (64, 64))
    
    testing_images.append([image_name, image])
# -

preds = []
for image in testing_images:
    name = image[0]
    pred = 1 if model.predict(image[1].reshape(1, 64, 64, -1)) > 0.5 else 0
    prediction = "Hindi" if pred == 1 else "Background"
    print(f"Prediction for image {name} is {prediction}")
    preds.append([name, pred])



StarcoderdataJupyterScriptsDedupFiltered