text_plain_output_1.png
from PIL import Image, ImageOps  # Install pillow instead of PIL

import numpy as np

import tensorflow as tf

model = load_model('/kaggle/input/ahsan-model-3-testing-implementation/from_kaggle/model_3.h5', compile=False)

model.summary()

class_names = ['happy', 'sad']

data = np.ndarray(shape=(48, 48, 1), dtype=np.float32)

image = Image.open('/kaggle/input/ahsan-model-3-testing-implementation/from_kaggle/dataset/sad/PrivateTest_568359.jpg').convert('RGB')

gray_image = image.convert('L')

size = (48, 48)
image = ImageOps.fit(gray_image, size, Image.Resampling.LANCZOS)

image_array = np.asarray(image)

image_array.shape

normalized_image_array = image_array.astype(np.float32) / 127.5 - 1

data_tensor = tf.convert_to_tensor(data, dtype=tf.float32)

data_tensor = tf.expand_dims(data_tensor, axis=0)

data_tensor.shape

prediction = model.predict(data_tensor)
index = np.argmax(prediction)
class_name = class_names[index]
confidence_score = prediction[0][index]