'how to predict a single image using already trained model in keras

I reeferred https://www.kaggle.com/code/lsind18/gemstones-multiclass-classification-cnn to train a model.

According to the above referred source,the test images are included as sub folders in the root directory.(That is the Test folder has sub folders as Ruby,Jade,Sapphire etc..).And they have predicted by using below code and shows the predicted value..

f,ax = plt.subplots(1,1) 
f.subplots_adjust(0,0,2,2)
for i in range(0,1,1):
    for j in range(0,1,1):
        rnd_number = randint(0,len(Test_Imgs))
        pred_image = model.predict([prepare('C:/Users/User/Desktop/pp1/images/test/sapphire blue_6')])
        pred_class = model.predict_classes(pred_image)[0]
        pred_prob = model.predict(pred_image).reshape(5)
        act = CLASSES[Test_Lbls[rnd_number]]
        ax[i,j].imshow(Test_Imgs[rnd_number])
        ax[i,j].imshow(pred_image[0])
        if(CLASSES[pred_class] != CLASSES[Test_Lbls[rnd_number]]):
            t = '{} [{}]'.format(CLASSES[pred_class], CLASSES[Test_Lbls[rnd_number]])
            ax[i,j].set_title(t, fontdict={'color': 'darkred'})
        else:
            t = '[OK] {}'.format(CLASSES[pred_class]) 
            ax[i,j].set_title(t)
        ax[i,j].axis('off')

What I want to know is by using the same code as above source to train the model and by using the trained model how can I predict a single image without storing inside a sub folder in the root directory.(That is inside my test folder there is an image called 'image.jpg').In other words using the trained model in https://www.kaggle.com/code/lsind18/gemstones-multiclass-classification-cnn I want to test just a single image and display the predicted value.

Any help is appreciated. Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source