S
S
Sultan5552020-10-08 18:20:03
Python
Sultan555, 2020-10-08 18:20:03

How to change the code in Python so that at the end not random photos in the neural network are tested, but photos from the folder?

This is the code from Kaggle and this part from testing This code predicts a random photo from the dataset
And I have a question how to change the code so that it does not display a random photo, but a photo from a folder
here is a link to the Kaggle project https://www.kaggle.com/paoloripamonti /derma-diseas...
And this code is the very part of neural network testing

def load_image(filename):
    img = cv2.imread(os.path.join(BASE_DATASET_FOLDER, TEST_FOLDER, filename))
    img = cv2.resize(img, (IMAGE_SIZE[0], IMAGE_SIZE[1]) )
    img = img /255
    
    return img


def predict(image):
    probabilities = model.predict(np.asarray([img]))[0]
    class_idx = np.argmax(probabilities)
    
    return {classes[class_idx]: probabilities[class_idx]}

for idx, filename in enumerate(random.sample(test_generator.filenames, 10)):
    print("SOURCE: class: %s, file: %s" % (os.path.split(filename)[0], filename))
    
    img = load_image(filename)
    prediction = predict(img)
    print("PREDICTED: class: %s, confidence: %f" % (list(prediction.keys())[0], list(prediction.values())[0]))
    plt.imshow(img)
    plt.figure(idx)    
    plt.show()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav the Wise, 2020-10-08
@yungtitanium

Where is filename from?
If you are uploading a photo to this folder, then change filename to the file name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question