lmoroney / dlaicourse

Notebooks for learning deep learning
5.66k stars 5.37k forks source link

result of ###Running the Model in Course 1 - Part 8 - Lesson 3 - Notebook #105

Open mazzingkaizer opened 4 years ago

mazzingkaizer commented 4 years ago

Mr. Moroney, I always get a lot of help from your great courses. Thank you. ^^

The following is the result of ##Running the Model in Course 1 - Part 8 - Lesson 3 - which I modified and executed.
I modified the source code a little because I wanted to check the results on local PC. The execution result is MISS CLASSIFICATION RATIO: 14.0625 This is the rate at which a horse image is judged to be human or a person image is judged to be a horse. I think the rate of misjudgment is higher than expected.

How do I get this ratio close to zero percent?

------ modified source code "##Running the Model in Course 1 - Part 8 - Lesson 3 " ------- import numpy as np

from google.colab import files

from tensorflow.keras.preprocessing import image

uploaded = files.upload()

for fn in uploaded.keys():

valid_image_list = [ { 'path': validation_horse_dir, 'images': os.listdir(validation_horse_dir) }, { 'path': validation_human_dir, 'images': os.listdir(validation_human_dir) }]

total_image_cnt = len(os.listdir(validation_horse_dir)) + len(os.listdir(validation_human_dir)) miss_classification_count = 0 for valid_image in valid_image_list: for image_name in valid_image['images']:

predicting images

    path = '{}/{}'.format(valid_image['path'], image_name)
    #print("path:{}".format(path))
    img = image.load_img(path, target_size=(300, 300))
    x = image.img_to_array(img)
    x = np.expand_dims(x, axis=0)

    images = np.vstack([x])
    classes = model.predict(images, batch_size=10)
    #print(classes[0])
    if classes[0] > 0.5:
        if image_name.find("horse") > -1:
            miss_classification_count += 1
            res = "WRONG"
        else:
            res = "CORRECT"

        print("{} {} is a human : {}".format(classes[0], path, res))
    else:
        if image_name.find("human") > -1:
            miss_classification_count += 1
            res = "WRONG"
        else:
            res = "CORRECT"
        print("{} {} is a horse : {}".format(classes[0], path, res))

print("MISS CLASSIFICATION RATIO : {}".format((miss_classification_count / total_image_cnt) * 100))