|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# */AIPND-revision/intropyproject-classify-pet-images/check_images.py |
| 4 | +# |
| 5 | +# TODO 0: Add your information below for Programmer & Date Created. |
| 6 | +# PROGRAMMER: Christian Edelmayer |
| 7 | +# DATE CREATED: 10.01.2022 |
| 8 | +# REVISED DATE: |
| 9 | +# PURPOSE: Classifies pet images using a pretrained CNN model, compares these |
| 10 | +# classifications to the true identity of the pets in the images, and |
| 11 | +# summarizes how well the CNN performed on the image classification task. |
| 12 | +# Note that the true identity of the pet (or object) in the image is |
| 13 | +# indicated by the filename of the image. Therefore, your program must |
| 14 | +# first extract the pet image label from the filename before |
| 15 | +# classifying the images using the pretrained CNN model. With this |
| 16 | +# program we will be comparing the performance of 3 different CNN model |
| 17 | +# architectures to determine which provides the 'best' classification. |
| 18 | +# |
| 19 | +# Use argparse Expected Call with <> indicating expected user input: |
| 20 | +# python check_images.py --dir <directory with images> --arch <model> |
| 21 | +# --dogfile <file that contains dognames> |
| 22 | +# Example call: |
| 23 | +# python check_images.py --dir pet_images/ --arch vgg --dogfile dognames.txt |
| 24 | +## |
| 25 | + |
| 26 | +# Imports python modules |
| 27 | +from time import time, sleep |
| 28 | + |
| 29 | +# Imports print functions that check the lab |
| 30 | +from print_functions_for_lab_checks import * |
| 31 | + |
| 32 | +# Imports functions created for this program |
| 33 | +from get_input_args import get_input_args |
| 34 | +from get_pet_labels import get_pet_labels |
| 35 | +from classify_images import classify_images |
| 36 | +from adjust_results4_isadog import adjust_results4_isadog |
| 37 | +from calculates_results_stats import calculates_results_stats |
| 38 | +from print_results import print_results |
| 39 | + |
| 40 | +# Main program function defined below |
| 41 | +def main(): |
| 42 | + # TODO 0: Measures total program runtime by collecting start time |
| 43 | + start_time = time() |
| 44 | + |
| 45 | + # TODO 1: Define get_input_args function within the file get_input_args.py |
| 46 | + # This function retrieves 3 Command Line Arugments from user as input from |
| 47 | + # the user running the program from a terminal window. This function returns |
| 48 | + # the collection of these command line arguments from the function call as |
| 49 | + # the variable in_arg |
| 50 | + in_arg = get_input_args() |
| 51 | + |
| 52 | + # Function that checks command line arguments using in_arg |
| 53 | + check_command_line_arguments(in_arg) |
| 54 | + |
| 55 | + |
| 56 | + # TODO 2: Define get_pet_labels function within the file get_pet_labels.py |
| 57 | + # Once the get_pet_labels function has been defined replace 'None' |
| 58 | + # in the function call with in_arg.dir Once you have done the replacements |
| 59 | + # your function call should look like this: |
| 60 | + # get_pet_labels(in_arg.dir) |
| 61 | + # This function creates the results dictionary that contains the results, |
| 62 | + # this dictionary is returned from the function call as the variable results |
| 63 | + results = get_pet_labels(in_arg.dir) |
| 64 | + |
| 65 | + # Function that checks Pet Images in the results Dictionary using results |
| 66 | + check_creating_pet_image_labels(results) |
| 67 | + |
| 68 | + |
| 69 | + # TODO 3: Define classify_images function within the file classiy_images.py |
| 70 | + # Once the classify_images function has been defined replace first 'None' |
| 71 | + # in the function call with in_arg.dir and replace the last 'None' in the |
| 72 | + # function call with in_arg.arch Once you have done the replacements your |
| 73 | + # function call should look like this: |
| 74 | + # classify_images(in_arg.dir, results, in_arg.arch) |
| 75 | + # Creates Classifier Labels with classifier function, Compares Labels, |
| 76 | + # and adds these results to the results dictionary - results |
| 77 | + classify_images(in_arg.dir, results, in_arg.arch) |
| 78 | + |
| 79 | + # Function that checks Results Dictionary using results |
| 80 | + check_classifying_images(results) |
| 81 | + |
| 82 | + |
| 83 | + # TODO 4: Define adjust_results4_isadog function within the file adjust_results4_isadog.py |
| 84 | + # Once the adjust_results4_isadog function has been defined replace 'None' |
| 85 | + # in the function call with in_arg.dogfile Once you have done the |
| 86 | + # replacements your function call should look like this: |
| 87 | + # adjust_results4_isadog(results, in_arg.dogfile) |
| 88 | + # Adjusts the results dictionary to determine if classifier correctly |
| 89 | + # classified images as 'a dog' or 'not a dog'. This demonstrates if |
| 90 | + # model can correctly classify dog images as dogs (regardless of breed) |
| 91 | + adjust_results4_isadog(results, in_arg.dogfile) |
| 92 | + |
| 93 | + # Function that checks Results Dictionary for is-a-dog adjustment using results |
| 94 | + check_classifying_labels_as_dogs(results) |
| 95 | + |
| 96 | + |
| 97 | + # TODO 5: Define calculates_results_stats function within the file calculates_results_stats.py |
| 98 | + # This function creates the results statistics dictionary that contains a |
| 99 | + # summary of the results statistics (this includes counts & percentages). This |
| 100 | + # dictionary is returned from the function call as the variable results_stats |
| 101 | + # Calculates results of run and puts statistics in the Results Statistics |
| 102 | + # Dictionary - called results_stats |
| 103 | + results_stats = calculates_results_stats(results) |
| 104 | + |
| 105 | + # Function that checks Results Statistics Dictionary using results_stats |
| 106 | + check_calculating_results(results, results_stats) |
| 107 | + |
| 108 | + |
| 109 | + # TODO 6: Define print_results function within the file print_results.py |
| 110 | + # Once the print_results function has been defined replace 'None' |
| 111 | + # in the function call with in_arg.arch Once you have done the |
| 112 | + # replacements your function call should look like this: |
| 113 | + # print_results(results, results_stats, in_arg.arch, True, True) |
| 114 | + # Prints summary results, incorrect classifications of dogs (if requested) |
| 115 | + # and incorrectly classified breeds (if requested) |
| 116 | + print_results(results, results_stats, in_arg.arch, True, True) |
| 117 | + |
| 118 | + # TODO 0: Measure total program runtime by collecting end time |
| 119 | + end_time = time() |
| 120 | + |
| 121 | + # TODO 0: Computes overall runtime in seconds & prints it in hh:mm:ss format |
| 122 | + tot_time = end_time - start_time #calculate difference between end time and start time |
| 123 | + print("\n** Total Elapsed Runtime:", |
| 124 | + str(int((tot_time/3600)))+":"+str(int((tot_time%3600)/60))+":" |
| 125 | + +str(int((tot_time%3600)%60)) ) |
| 126 | + |
| 127 | + |
| 128 | +# Call to main function to run the program |
| 129 | +if __name__ == "__main__": |
| 130 | + main() |
0 commit comments