JUAN ROLON
  • Home
  • Machine Learning
  • Physics
  • About
cnn-image-classifier5

Convolutional Neural Networks for Dog Breed Identification¶

Part 5¶


Juan E. Rolon, 2018.¶


Image classifier:¶

In [81]:
#@Juan E. Rolon
#Added this function to save performance metrics to csv file and generate corresponding
#plots. It receives the checkpointe history object and a desired filename without 
#file extensions. It outputs plots and stores as .csv and .png file respectively.
# determines and returns whether the image contains a human, dog, or neither

def classify_image(predictor, img_path):
    img = cv2.imread(img_path)
    cv_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    imgplot = plt.imshow(cv_rgb)

    if face_detector(img_path):
        pred = predictor(img_path)
        breed = pred.rpartition('/')[-1].rpartition('.')[-1].replace('_', ' ')
        print("Human face detected in image")
        print("This human looks like a {}".format(breed))
        return
    elif dog_detector(img_path):
        pred = predictor(img_path)
        breed = pred.rpartition('/')[-1].rpartition('.')[-1].replace('_', ' ')
        print("Dog face detected in image")
        print("This dog looks like a {}".format(breed))
    else:
        print("Non identifiable dog nor human faces detected")

Testing the Algorithm on Several Different Image Categories¶

Criteria:

  • Algorithm identifies the most resembling dog breed for a human face.

  • Algorithm determines whether an image from a related animal can be mistakely confused with a dog breed

Testing the Algorithm on Sample Images!¶

Here we test the algorithm on at least six images. We can use any images containing humans and dogs. Here we use at least two human and two dog images.

Below we assess the algorithm performance and points of improvement.

Results:¶

  • I tested the algorithm on several images not contained in the original datasets. The output was much better when compared to the previous implementations.

  • For images containing dogs, the algorithm correctly identified the corresponding dog breed on each image in agreement with the reported accuracy of 83%.

  • I also fed the images of a Cat and a Wolf and in both cases the algorithm did not detect a dog nor a human face.

  • I fed the images of 3 human faces, including the snapshot of an anime movie. In all cases the algorithm detected a human face.

Points of improvement:¶

Segment images to allow the image detector and/or classifier scan more than one face.

As is, the algorithm cannot identify more than one breed in an image containing several dogs of different breeds. Below, I fed an image containing 3 dogs and the algorithm classified (correctly) one dog while ignoring the others. My intuition is that it picked the one with the highest probability.

Allow or augment datasets for wider color variations and interlayering with similar objects.

It seems that color variations due to interlayering with nearby similar objects obfuscates the algorithm. I fed the algorithm an image of a Labrador Retriever seated together with cat with similar hair color and higher orange tonality. I also fed an image of a single Labrador with higher orange tonality. In both cases, the algorithm classified the image incorrectly as being a Golden Retriever

Fine-tune the algorithm to better classify images of animals closely resembling a dog.

I fed the algorithm with an image of a Dingo (a feral wild dog) which the algorithm classified incorrectly as a Collie. A possible solution is to write separate face detectors for closely resembling species.

Succesful cases:¶

In [85]:
classify_image(Resnet50_predict_breed,'my_test_images/Greyhound.jpg')
Dog face detected in image
This dog looks like a Italian greyhound
In [96]:
classify_image(Resnet50_predict_breed,'my_test_images/Husky.jpg')
Human face detected in image
This human looks like a Alaskan malamute
In [111]:
classify_image(Resnet50_predict_breed,'my_test_images/Wolf.jpg')
Non identifiable dog nor human faces detected

Non-standard cases suggesting need for improvement:¶

In [105]:
classify_image(Resnet50_predict_breed,'my_test_images/3dogs.jpg')
Dog face detected in image
This dog looks like a Doberman pinscher
In [ ]:
 
Powered by Create your own unique website with customizable templates.
  • Home
  • Machine Learning
  • Physics
  • About