I am using the below code to detect dark vs well-lit images but it is not giving accurate results and is giving very long floating values like .00000000123 etc.
#!/usr/bin/env python3
import cv2
import tensorflow as tf
import numpy as np
import os
path = '/home/..../Downloads/normal_images'
files = os.listdir(path)
# Load the pre-trained MobileNetV2 model
model = tf.keras.applications.MobileNetV2(weights='imagenet')
x = np.float32(0.5)
for file_name in files:
file_path = os.path.join(path, file_name)
# Load an image to classify
img = cv2.imread(file_path)
img = cv2.resize(img, (224, 224))
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
np.set_printoptions(suppress=True, precision=20)
img = np.expand_dims(img, axis=0)
probs = model.predict(img)
prob_val = probs[0][0]
if (prob_val > x):
not_dark +=1
else:
dark +=1
print(f"No.of dark images identified: {dark}")
print(f"No.of normal images identified: {not_dark}")
Is my approach correct ?