1

i'm doing a relatively simple binary classification model using ResNet50 as transfer learning model. Using Predict on multiple or single images causes various different errors that i mention below. I didn't know what exactly to use as a question title because I'm confused about more than one thing.

im suspicious that the way i split the data is the causing issue, so here is how i split them using DataGenerator:

test_datagen = ImageDataGenerator(rescale=1./255)
test_generator = test_datagen.flow_from_directory(
        test_dir,
        target_size=(224, 224),
        batch_size=32,
        class_mode='binary',
        shuffle=True,seed=42
        )

i used a shuffling technique because i wasn't sure if its going to be unbiased or not when using it:

indices = list(range(len(test_generator)))
random.shuffle(indices)
shuffled_images = [test_generator[index][0] for index in indices]
shuffled_labels = [test_generator[index][1] for index in indices]
y_true=np.concatenate(shuffled_labels)
x_test=np.concatenate(shuffled_images)

When i use x_test using the saved model it always has the same accuracy and the confusion matrix also doesn't change When i tried to input single images the output was always the same,note that i had to resize the shape of the image as it gave an error: ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 224, 224, 3), found shape=(32, 224, 3) so i used this to fix it:

img = cv2.imread(path)
img.resize([1,224,224,3])
prediction = model.predict(img)

in addition to this i tried to show the image before i use predict:

img.resize([224,224,3])
plt.imshow(img)

it shows some images as totally black, others as images with white parallel lines, others the actual image, its all just random. in any way the output is always 1. i apologize if there are issues with how i explained the problem because i'm new to models, ask away please if there are confusing parts.

Heba
  • 31
  • 3

0 Answers0