def main(): # start the timer and parse any args from the user start_time = time() in_arg = get_input_args() check_command_line_arguments(in_arg) # infer the correct answers from the image file names results = get_pet_labels(in_arg.dir) check_creating_pet_image_labels(results) # predict the result for each image, for the given architecture classify_images(in_arg.dir, results, in_arg.arch) check_classifying_images(results) # aggregate the results to dog not-dog level adjust_results4_isadog(results, in_arg.dogfile) check_classifying_labels_as_dogs(results) # calculate accuracy and some other aggregate statistics results_stats = calculates_results_stats(results) check_calculating_results(results, results_stats) # print the final results for this architecture and stop the timer print_results(results, results_stats, in_arg.arch, True, True) end_time = time() tot_time = (end_time - start_time) print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60))) import pickle with open("results_stats.pickle", "wb") as f: pickle.dump(results_stats, f) print() print() print("****** FINAL RESULTS *******") print() print() print("{} {} {} {} {}".format( "Architecture", "~Dog", "Dog", "Breed", "Label")) print("{}{}{:.2f} {:.2f} {:.2f} {:.2f}".format( in_arg.arch, " " * (19 - len(in_arg.arch)), results_stats['pct_correct_notdogs'], results_stats['pct_correct_dogs'], results_stats['pct_correct_breed'], results_stats['pct_match'])) print() print() print("*******************************")
def main(): # log start time start_time = time() # get input in_arg = get_input_args() # check input check_command_line_arguments(in_arg) # get pet labels results = get_pet_labels(in_arg.dir) # check pet labels check_creating_pet_image_labels(results) # classify images classify_images(in_arg.dir, results, in_arg.arch) # check image classification check_classifying_images(results) # adjust results for dogs adjust_results4_isadog(results, in_arg.dogfile) # check adjusted results for dogs check_classifying_labels_as_dogs(results) # get results stats results_stats = calculates_results_stats(results) # check results stats check_calculating_results(results, results_stats) # TODO 6: Define print_results function within the file print_results.py # Once the print_results function has been defined replace 'None' # in the function call with in_arg.arch Once you have done the # replacements your function call should look like this: # print_results(results, results_stats, in_arg.arch, True, True) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, True, True) end_time = time() tot_time = end_time - start_time print("\n** Total Elapsed Runtime:", str(int((tot_time/3600)))+":"+str(int((tot_time%3600)/60))+":" +str(int((tot_time%3600)%60)) )
def main(): # Record the start time of main function start_time = time() # Get input arguments in_arg = get_input_args() # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) # Creates the results dictionary that contains the results results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) # Creates Classifier Labels with classifier function, Compares Labels, # and adds these results to the results dictionary - results classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) # Adjusts the results dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # Calculates results of run and puts statistics in the Results Statistics # Dictionary - called results_stats results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, True, True) # Record the end time of main function end_time = time() # Calculate the total runtime in seconds & prints it in hh:mm:ss format tot_time = end_time - start_time print("\n** Total Elapsed Runtime:", str(int((tot_time/3600)))+":"+str(int((tot_time%3600)/60))+":" +str(int((tot_time%3600)%60)) )
def main(): # Measures total program runtime by collecting start time start_time = time() # Creates & retrieves Command Line Arugments in_arg = get_input_args() # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) # Creates Pet Image Labels by creating a dictionary answers_dic = get_pet_labels(in_arg.dir) # Function that checks Pet Images Dictionary- answers_dic check_creating_pet_image_labels(answers_dic) # Creates Classifier Labels with classifier function, Compares Labels, # and creates a results dictionary result_dic = classify_images(in_arg.dir, answers_dic, in_arg.arch) # Function that checks Results Dictionary - result_dic check_classifying_images(result_dic) # Adjusts the results dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(result_dic, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment- result_dic check_classifying_labels_as_dogs(result_dic) # Calculates results of run and puts statistics in results_stats_dic results_stats_dic = calculates_results_stats(result_dic) # Function that checks Results Stats Dictionary - results_stats_dic check_calculating_results(result_dic, results_stats_dic) # Prints summary results, incorrect classifications of dogs # and breeds if requested print_results(result_dic, results_stats_dic, in_arg.arch, True, True) # Measure total program runtime by collecting end time end_time = time() # Computes overall runtime in seconds & prints it in hh:mm:ss format tot_time = end_time - start_time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60)))
def main(): start_time = time() in_arg = get_input_args() check_command_line_arguments(in_arg) results = get_pet_labels(in_arg.dir) check_creating_pet_image_labels(results) classify_images(in_arg.dir, results, in_arg.arch) check_classifying_images(results) adjust_results4_isadog(results, in_arg.dogfile) check_classifying_labels_as_dogs(results) results_stats = calculates_results_stats(results) check_calculating_results(results, results_stats) print_results(results, results_stats, in_arg.arch, True, True)
def main(): start_time = time() # start_time from time module (0) #1 in_arg = get_input_args() #read command line args, using argparse mod(1) check_command_line_arguments(in_arg) #prints command line arguments (1) #2 results = get_pet_labels( in_arg.dir ) #creates dictionary with key: file_name & value: [pet_label] check_creating_pet_image_labels(results) # prints 10 of key value pairs #3 classify_images(in_arg.dir, results, in_arg.arch) check_classifying_images(results) adjust_results4_isadog(results, in_arg.dogfile) check_classifying_labels_as_dogs(results) results_stats = calculates_results_stats(results) check_calculating_results(results, results_stats) print_results(results, results_stats, in_arg.arch, True, True) #python check_images.py --dir pet_images/ --arch resnet --dogfile dognames.txt --> 6 seconds, but pct_correct_dogs is wrong #python check_images.py --dir pet_images/ --arch alexnet --dogfile dognames.txt --> 3 seconds #python check_images.py --dir pet_images/ --arch vgg --dogfile dognames.txt --> 37 seconds end_time = time() tot_time = end_time - start_time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60))) table1 = PrettyTable() table1.field_names = [ "# Total Images", "# Dog Images", "# Not-a-Dog Images" ] table1.add_row([40, 30, 10]) print(table1) print("\n\n\n") table2 = PrettyTable() table2.field_names = [ "CNN Model Architecture: ", "% Not-a-Dog Correct", "% Dogs Corrects", "% Breeds Correct", "% Match Labels", "Runtime (seconds)" ] table2.add_row(["ResNet", "90%", "100%", "90%", "82.5%", 6]) table2.add_row(["AlexNet", "100%", "100%", "80%", "75%", 3]) table2.add_row(["VGG", "100%", "100%", "93.3%", "87.5%", 35]) print(table2) print( "The model VGG was the one that was able to classify 'dogs' and 'not-a-dog' with 100% accuracy and had the best performance regarding breed classification with 93.3% accuracy. The Model AlexNet was the most efficient with the fastest runtime at only 3 seconds but still images 100% accuracy for identifying dogs correctly" )
def main(): start_time = time() # This function retrieves 3 Command Line Arugments from user as input from # the user running the program from a terminal window. in_arg = get_input_args() #Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) #Creates the results dictionary that contains the results results = get_pet_labels(in_arg.dir) #Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) #Creates Classifier Labels with classifier function, Compares Labels, #and adds these results to the results dictionary classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) #Adjusts the results dictionary to determine if classifier correctly classified images as 'a dog' or 'not a dog'. adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # Calculates results of run and puts statistics in the Results Statistics # Dictionary results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, True, True) end_time = time() tot_time = end_time - start_time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60)))
def main(): # Start measuring the time of program running start_time = time() # Get command line arguments in_arg = get_input_args() # Check command line arguments check_command_line_arguments(in_arg) # Get pet labels as Dictionary of filename: list of one label results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) # Classify images by adding classifier label and comparison label # for each list in key:object pairs in result Dictionary classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) # Adjusts the results dictionary to determine if classifier correctly classified images 'as a dog' or 'not a dog' adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # Calculates results of run and puts statistics in the Results Statistics results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # Print results print_results(results, results_stats, in_arg.arch, True, True) # End measuring the time of program running end_time = time() # Print total time of program running tot_time = end_time - start_time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60)))
def main(): start_time = timer() in_arg = get_input_args() # Function that checks command line arguments using in_arg if in_arg.verbose: check_command_line_arguments(in_arg) results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results if in_arg.verbose: check_creating_pet_image_labels(results) classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results if in_arg.verbose: check_classifying_images(results) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results if in_arg.verbose: check_classifying_labels_as_dogs(results) results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats if in_arg.verbose: check_calculating_results(results, results_stats) print_results(results, results_stats, in_arg.arch, True, True) end_time = timer() tot_time = end_time - start_time print("\n[*] Total Elapsed Runtime: {:02d}:{:02d}:{}".format( int(tot_time / 3600), # hours int(tot_time % 3600 / 60), # minutes round(tot_time % 3600 % 60, 5))) # seconds if in_arg.compare: table_comparison(results_stats)
def main(): # Measures total program runtime by collecting start time start_time = time() # This function retrieves 3 Command Line Arugments from user as input from # the user running the program from a terminal window. This function returns # the collection of these command line arguments from the function call as # the variable in_arg in_arg = get_input_args() check_command_line_arguments(in_arg) # This function creates the results dictionary that contains the results, # this dictionary is returned from the function call as the variable results results = get_pet_labels(in_arg.dir) check_creating_pet_image_labels(results) # Creates Classifier Labels with classifier function, Compares Labels, # and adds these results to the results dictionary - results classify_images(in_arg.dir, results, in_arg.arch) check_classifying_images(results) # Adjusts the results dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(results, in_arg.dogfile) check_classifying_labels_as_dogs(results) # Called function creates the results statistics dictionary that contains a # summary of the results statistics (this includes counts & percentages). This # dictionary is returned from the function call as the variable results_stats # Calculates results of run and puts statistics in the Results Statistics # Dictionary - called results_stats results_stats = calculates_results_stats(results) check_calculating_results(results, results_stats) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, True, True) end_time = time() tot_time = end_time - start_time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60)))
def main(): # TODO 0: Measures total program runtime by collecting start time start_time = time() in_arg = get_input_args() # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) try: print_results(results, results_stats, in_arg.arch, True, True) except ZeroDivisionError: print("Warning ! Division by zero !") end_time = time() tot_time = end_time - start_time #calculate difference between end time and start time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60)))
def main(): start_time = time() in_arg = get_input_args() check_command_line_arguments(in_arg) results = get_pet_labels(in_arg.dir) check_creating_pet_image_labels(results) classify_images(in_arg.dir, results, in_arg.arch) check_classifying_images(results) adjust_results4_isadog(results, in_arg.dogfile) check_classifying_labels_as_dogs(results) results_stats = calculates_results_stats(results) check_calculating_results(results, results_stats) print_results(results, results_stats, in_arg.arch, True, True) sleep(10) end_time = time() tot_time = end_time - start_time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60)))
def main(): start_time = time() in_arg = get_input_args() results = get_pet_labels(in_arg.dir) classify_images(in_arg.dir, results, in_arg.arch) adjust_results4_isadog(results, in_arg.dogfile) results_stats = calculates_results_stats(results) print_results(results, results_stats, in_arg.arch, True, True) end_time = time() tot_time = end_time - start_time #calculate difference between end time and start time print("\n** Total Elapsed Runtime:", str(int((tot_time/3600)))+":"+str(int((tot_time%3600)/60))+":" +str(int((tot_time%3600)%60)) )
def main(): start_time = time() in_arg = get_input_args() # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) print_results(results, results_stats, in_arg.arch, True, True) end_time = time() tot_time = end_time - start_time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60)))
def main(): start_time = time() # Collecting start time in_arg = get_input_args() # This function returns command line arguments check_command_line_arguments(in_arg) # Checks command line argument results = get_pet_labels(in_arg.dir) # Creates the results dictionary check_creating_pet_image_labels( results) # Checks pet images in the results Dictionary # Creates Classifier Labels with classifier function, Compares Labels, # and adds these results to the results dictionary - results classify_images(in_arg.dir, results, in_arg.arch) check_classifying_images( results) # Checks Results Dictionary using results adjust_results4_isadog(results, in_arg.dogfile) # Adjusts the results dictionary check_classifying_labels_as_dogs( results) # Checks Results Dictionary for is-a-dog adjustment results_stats = calculates_results_stats( results) # Calculates results of run check_calculating_results( results, results_stats) # Checks Results Statistics Dictionary print_results(results, results_stats, in_arg.arch, True, True) #Prints summary results end_time = time() # Collecting end time # Computes overall runtime in seconds & prints it in hh:mm:ss format tot_time = end_time - start_time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60)))
def main(): # TODO 0: Measures total program runtime by collecting start time start_time = time() # creates and retrieves command Line Arguments in_arg = get_input_args() # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) # Creates pet image labels by creating a dictionary answers_dic = get_pet_labels(in_arg.dir) check_creating_pet_image_labels(answers_dic) # Creates classifier labels with classifier function, compares labbels and createsa results # dictionary result_dic = classify_images(in_arg.dir, answers_dic, in_arg.arch) # Function that checks results dictionary result_dic check_classifying_images(result_dic) # Adjusts the results dictionary to determine if classifier correctly classified # images 'a dog' # or 'not a dog' adjust_results4_isadog(result_dic, in_arg.dogfile) # Function that checks results dictionary for is-a -dog adjustment - result-dic check_classifying_labels_as_dogs(result_dic) # Calculates results of run and puts statistics in results_stats_dic results_stats_dic = calculates_results_stats(result_dic) # Function that checks results stats dictionary - results_stats_dic check_calculating_results(result_dic, results_stats_dic) # Prints Summary results, incorrect classifications of dogs and breeds if requested print_results(result_dic, results_stats_dic, in_arg.arch, True, True) # Measure total program runtime by collecting end time end_time = time() # Computes overall runtime in seconds and prints it hh:mm:ss format tot_time = end_time - start_time print( '\n** Total elapsed runtime:', str(int((tot_time / 3600))) + ':' + str(int( (tot_time % 3600) / 60)) + ':' + str(int((tot_time % 3600) % 60)))
def main(): #TODO 0 ------------------------------------------------------------------ start_time = time.time() # Todo 1 in_arg = get_input_args() check_command_line_arguments(in_arg) #TODO 2 results_dic = get_pet_labels(in_arg.dir) #TODO 3 results = classify_images(in_arg.dir, results_dic, in_arg.arch) #updated Dict #TODO 4 results_dic= adjust_results4_isadog(results, in_arg.dogfile) # TODO 5 results_stats = calculates_results_stats(results) # TODO 6 print_results(results_dic, results_stats, in_arg.arch, True, True) #TODO 0 end_time = time.time() tot_time = end_time - start_time print("\n** Total Elapsed Runtime:", str(int((tot_time/3600)))+":"+str(int((tot_time%3600)/60))+":" +str(int((tot_time%3600)%60)) )
def main(): # TODO 0: Measures total program runtime by collecting start time start_time = time() sleep(75) # TODO 1: Define get_input_args function within the file get_input_args.py # This function retrieves 3 Command Line Arugments from user as input from # the user running the program from a terminal window. This function returns # the collection of these command line arguments from the function call as # the variable in_arg # TODO 2: Define get_pet_labels function within the file get_pet_labels.py # Once the get_pet_labels function has been defined replace 'None' # in the function call with in_arg.dir Once you have done the replacements # your function call should look like this: # get_pet_labels(in_arg.dir) # This function creates the results dictionary that contains the results, # this dictionary is returned from the function call as the variable results results = get_pet_labels(in_arg.dir) from os import listdir filename_list = listdir("pet_images/") print("\nPrints 10 filenames from folder pet_images/") for idx in range(0, 10, 1): print("{:2d} file: {:>25}".format(idx + 1, filename_list[idx])) results_dic = dict() items_in_dic = len(results_dic) print("\nEmpty Dictionary results_dic - n items=", items_in_dic) filenames = ["beagle_0239.jpg", "Boston_terrier_02259.jpg"] pet_labels = ["beagle", "boston terrier"] for idx in range(0, len(filenames), 1): if filenames[idx] not in results_dic: results_dic[filenames[idx]] = [pet_labels[idx]] else: print("** Warning: Key=", filenames[idx], "already exists in results_dic with value =", results_dic[filenames[idx]]) print("\nPrinting all key-value pairs in dictionary results_dic:") for key in results_dic: print("Filename=", key, " Pet Label=", results_dic[key][0]) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) # TODO 3: Define classify_images function within the file classify_images.py # Once the classify_images function has been defined replace first 'None' # in the function call with in_arg.dir and replace the last 'None' in the # function call with in_arg.arch Once you have done the replacements your # function call should look like this: # classify_images(in_arg.dir, results, in_arg.arch) # Creates Classifier Labels with classifier function, Compares Labels, # and adds these results to the results dictionary - results classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) # TODO 4: Define adjust_results4_isadog function within the file adjust_results4_isadog.py # Once the adjust_results4_isadog function has been defined replace 'None' # in the function call with in_arg.dogfile Once you have done the # replacements your function call should look like this: # adjust_results4_isadog(results, in_arg.dogfile) # Adjusts the results dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # TODO 5: Define calculates_results_stats function within the file calculates_results_stats.py # This function creates the results statistics dictionary that contains a # summary of the results statistics (this includes counts & percentages). This # dictionary is returned from the function call as the variable results_stats # Calculates results of run and puts statistics in the Results Statistics # Dictionary - called results_stats results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # TODO 6: Define print_results function within the file print_results.py # Once the print_results function has been defined replace 'None' # in the function call with in_arg.arch Once you have done the # replacements your function call should look like this: # print_results(results, results_stats, in_arg.arch, True, True) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, True, True) # TODO 0: Measure total program runtime by collecting end time end_time = time() # TODO 0: Computes overall runtime in seconds & prints it in hh:mm:ss format tot_time = end_time - start_time print("\nTotal Elapsed Runtime:", tot_time, "in seconds.") print( "\nTotal Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( ((tot_time % 3600) / 60))) + ":" + str(int(((tot_time % 3600) % 60))))
def main(): # TODO 0: Measures total program runtime by collecting start time start_time = time() # TODO 1: Define get_input_args function within the file get_input_args.py # This function retrieves 3 Command Line Arugments from user as input from # the user running the program from a terminal window. This function returns # the collection of these command line arguments from the function call as # the variable in_arg #*** Implemented in VS CODE as launch.json configuration choice for each model in_arg = get_input_args() # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) # From pathlib use Path to convert the relative path to an absolute. # There is some discussion that .absolute() is hidden and .resolve() should be used, but # test results from the field suggest that absolute works and resolve does not. Another # suggestion was to use Path.cwd() / path. # https://discuss.python.org/t/pathlib-absolute-vs-resolve/2573 in_arg.dir = Path(in_arg.dir).absolute() # TODO 2: Define get_pet_labels function within the file get_pet_labels.py # Once the get_pet_labels function has been defined replace 'None' # in the function call with in_arg.dir Once you have done the replacements # your function call should look like this: # get_pet_labels(in_arg.dir) # This function creates the results dictionary that contains the results, # this dictionary is returned from the function call as the variable results # According to get_pet_labels function documentation, the image.dir argument passed # in is supposed to be a 'full' path, while the command line path argument can be # a relative path, that's why in_arg.dir is changed to a full path above results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) # TODO 3: Define classify_images function within the file classiy_images.py # Once the classify_images function has been defined replace first 'None' # in the function call with in_arg.dir and replace the last 'None' in the # function call with in_arg.arch Once you have done the replacements your # function call should look like this: # classify_images(in_arg.dir, results, in_arg.arch) # Creates Classifier Labels with classifier function, Compares Labels, # and adds these results to the results dictionary - results classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) # TODO 4: Define adjust_results4_isadog function within the file adjust_results4_isadog.py # Once the adjust_results4_isadog function has been defined replace 'None' # in the function call with in_arg.dogfile Once you have done the # replacements your function call should look like this: # adjust_results4_isadog(results, in_arg.dogfile) # Adjusts the results dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # TODO 5: Define calculates_results_stats function within the file calculates_results_stats.py # This function creates the results statistics dictionary that contains a # summary of the results statistics (this includes counts & percentages). This # dictionary is returned from the function call as the variable results_stats # Calculates results of run and puts statistics in the Results Statistics # Dictionary - called results_stats results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # TODO 6: Define print_results function within the file print_results.py # Once the print_results function has been defined replace 'None' # in the function call with in_arg.arch Once you have done the # replacements your function call should look like this: # print_results(results, results_stats, in_arg.arch, True, True) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, in_arg.incorrect_dog, in_arg.incorrect_breed) # TODO 0: Measure total program runtime by collecting end time # TODO 0: Computes overall runtime in seconds & prints it in hh:mm:ss format # From: https://stackoverflow.com/questions/7999935/python-datetime-to-string-without-microsecond-component hours, remainder = divmod(time() - start_time, 3600) minutes, seconds = divmod(remainder, 60) print('\nExecution time {:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds)))
fh.close() image_dir = pet_images model_name = arch img_path = image_dir print("Command Line Args: " + "image dir: " + image_dir + " model name: " + model_name + " file: " + dogfile) except Exception as e: import sys print("ERROR: Problem With Command Line Arguments") sys.exit(1) my_dog_images_dict = {} type_tuple = get_pet_labels( image_dir) #***type tuple contains actual image labels doggie_tuple = [] not_doggie_tuple = [] dog_namez = dog_namez.replace(",", "") #contains list with broken up dog names! dog_namez = dog_namez.split("\n") for x in type_tuple: if x not in doggie_tuple: if x[1] in dog_namez: print("Dog Name Label Found: " + x[2]) doggie_tuple.append(x) #identified dog names in file dir print "\n"
def main(): # TODO 0: Measures total program runtime by collecting start time start_time = time() # TODO 1: Define get_input_args function within the file get_input_args.py # This function retrieves 3 Command Line Arugments from user as input from # the user running the program from a terminal window. This function returns # the collection of these command line arguments from the function call as # the variable in_arg in_arg = get_input_args() # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) # TODO 2: Define get_pet_labels function within the file get_pet_labels.py # Once the get_pet_labels function has been defined replace 'None' # in the function call with in_arg.dir Once you have done the replacements # your function call should look like this: # get_pet_labels(in_arg.dir) # This function creates the results dictionary that contains the results, # this dictionary is returned from the function call as the variable results results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) # TODO 3: Define classify_images function within the file classiy_images.py # Once the classify_images function has been defined replace first 'None' # in the function call with in_arg.dir and replace the last 'None' in the # function call with in_arg.arch Once you have done the replacements your # function call should look like this: # classify_images(in_arg.dir, results, in_arg.arch) # Creates Classifier Labels with classifier function, Compares Labels, # and adds these results to the results dictionary - results classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) # TODO 4: Define adjust_results4_isadog function within the file adjust_results4_isadog.py # Once the adjust_results4_isadog function has been defined replace 'None' # in the function call with in_arg.dogfile Once you have done the # replacements your function call should look like this: # adjust_results4_isadog(results, in_arg.dogfile) # Adjusts the results dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # TODO 5: Define calculates_results_stats function within the file calculates_results_stats.py # This function creates the results statistics dictionary that contains a # summary of the results statistics (this includes counts & percentages). This # dictionary is returned from the function call as the variable results_stats # Calculates results of run and puts statistics in the Results Statistics # Dictionary - called results_stats results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # TODO 6: Define print_results function within the file print_results.py # Once the print_results function has been defined replace 'None' # in the function call with in_arg.arch Once you have done the # replacements your function call should look like this: # print_results(results, results_stats, in_arg.arch, True, True) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg, True, True) # TODO 0: Measure total program runtime by collecting end time end_time = time() # TODO 0: Computes overall runtime in seconds & prints it in hh:mm:ss format tot_time = start_time + end_time#calculate difference between end time and start time print("\n** Total Elapsed Runtime:", str(int((tot_time/3600)))+":"+str(int((tot_time%3600)/60))+":" +str(int((tot_time%3600)%60)) )
from calculates_results_stats import calculates_results_stats from print_results import print_results # Main program function defined below def main(): start_time = time() in_arg = get_input_args() check_command_line_arguments(in_arg) results = get_pet_labels(None) check_creating_pet_image_labels(results) classify_images(None, results, None) check_classifying_images(results) adjust_results4_isadog(results, None)
def test_classify_images(self): results_dic = get_pet_labels(images_dir) classify_images(images_dir, results_dic, 'vgg') self.assertEqual(results_dic[filename], ['boston terrier', 'Boston bull, Boston terrier', 1])
def main(): # store results dicts for each architecture arch_results = [] # TODO 1: Define get_input_args function within the file get_input_args.py # This function retrieves 3 Command Line Arugments from user as input from # the user running the program from a terminal window. This function returns # the collection of these command line arguments from the function call as # the variable in_arg in_arg = get_input_args() print("Argument 1:", in_arg.dir) print("Argument 2:", in_arg.arch) print("Argument 3:", in_arg.dogfile) # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) archs = in_arg.arch.split(",") for arch in archs: # TODO 0: Measures total program runtime by collecting start time start_time = time() # TODO 2: Define get_pet_labels function within the file get_pet_labels.py # Once the get_pet_labels function has been defined replace "None" # in the function call with in_arg.dir Once you have done the replacements # your function call should look like this: # get_pet_labels(in_arg.dir) # This function creates the results dictionary that contains the results, # this dictionary is returned from the function call as the variable results results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) # TODO 3: Define classify_images function within the file classiy_images.py # Once the classify_images function has been defined replace first "None" # in the function call with in_arg.dir and replace the last "None" in the # function call with in_arg.arch Once you have done the replacements your # function call should look like this: # classify_images(in_arg.dir, results, in_arg.arch) # Creates Classifier Labels with classifier function, Compares Labels, # and adds these results to the results dictionary - results classify_images(in_arg.dir, results, arch) # Function that checks Results Dictionary using results check_classifying_images(results) # TODO 4: Define adjust_results4_isadog function within the file adjust_results4_isadog.py # Once the adjust_results4_isadog function has been defined replace "None" # in the function call with in_arg.dogfile Once you have done the # replacements your function call should look like this: # adjust_results4_isadog(results, in_arg.dogfile) # Adjusts the results dictionary to determine if classifier correctly # classified images as "a dog" or "not a dog". This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # TODO 5: Define calculates_results_stats function within the file calculates_results_stats.py # This function creates the results statistics dictionary that contains a # summary of the results statistics (this includes counts & percentages). This # dictionary is returned from the function call as the variable results_stats # Calculates results of run and puts statistics in the Results Statistics # Dictionary - called results_stats results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # TODO 6: Define print_results function within the file print_results.py # Once the print_results function has been defined replace "None" # in the function call with in_arg.arch Once you have done the # replacements your function call should look like this: # print_results(results, results_stats, in_arg.arch, True, True) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, arch, True, True) # TODO 0: Measure total program runtime by collecting end time end_time = time() # TODO 0: Computes overall runtime in seconds tot_time = end_time - start_time results_stats["exec_time"] = tot_time results_stats["arch"] = arch arch_results.append(results_stats) # prints execution time in in hh:mm:ss format print("\n** Total Elapsed Runtime:", format_time(tot_time) ) # print architecture performance print("\n**Architecture Performance**\n") print("{:20}: {}".format("# Total Images", arch_results[0]["n_images"])) print("{:20}: {}".format("# Dog Images", arch_results[0]["n_dogs_img"])) print("{:20}: {}".format("# Not-Dog Images", arch_results[0]["n_notdogs_img"])) print("\n{:20} | {:20} | {:20} | {:20} | {:20} | {:20}".format("Architecture", "% Not-Dog Correct", "% Dog Correct", "% Breed Correct", "% Label Match", "Processing time")) print("{:_<135}".format("")) for ar in arch_results: print("{:20} | {:19.2f}% | {:19.2f}% | {:19.2f}% | {:19.2f}% | {:>20}".format(ar["arch"].upper(), ar["pct_correct_notdogs"], ar["pct_correct_dogs"], ar["pct_correct_breed"], ar["pct_match"], format_time_millis(ar["exec_time"]) ))
def main(): # Measures total program runtime by collecting start time start_time = time() # Function get_input_args is defined in the file get_input_args.py # This function retrieves 3 Command Line Arugments as input from # the user running the program from a terminal window. This function returns # the collection of these Command Line Arguments from the function call as # the variable in_arg. in_arg = get_input_args() # Function that checks Command Line Arguments using in_arg check_command_line_arguments(in_arg) # Function get_pet_labels is defined in the file get_pet_labels.py # This function creates the Results Dictionary that contains the results. # This dictionary is returned from the function call as the variable results. results = get_pet_labels(in_arg.dir) # Function that checks pet images in the Results Dictionary using results check_creating_pet_image_labels(results) # Function classify_images is defined in the file classiy_images.py # Creates classifier labels with classifier function, compares labels, # and adds these results to the Results Dictionary (results). classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) # Function adjust_results4_isadog is defined in the file adjust_results4_isadog.py # Adjusts the Results Dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed). adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # Function calculates_results_stats is defined in the file calculates_results_stats.py # This function creates the Results Statistics Dictionary that contains a # summary of the results statistics (this includes counts & percentages). This # dictionary is returned from the function call as the variable results_stats. # Calculates results of run and puts statistics in the Results Statistics # Dictionary (results_stats). results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # Function print_results is deined within the file print_results.py # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, True, True) # Measure total program runtime by collecting end time end_time = time() # Computes overall runtime in seconds & print it in hh:mm:ss format # Calculate difference between end time and start time tot_time = end_time - start_time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(round( (tot_time % 3600) % 60)))
def main(): # TODO 0: Measures total program runtime by collecting start time start_time = time() # TODO 1: Define get_input_args function within the file get_input_args.py # This function retrieves 3 Command Line Arugments from user as input from # the user running the program from a terminal window. This function returns # the collection of these command line arguments from the function call as # the variable in_arg in_arg = get_input_args() # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) # TODO 2: Define get_pet_labels function within the file get_pet_labels.py # Once the get_pet_labels function has been defined replace 'None' # in the function call with in_arg.dir Once you have done the replacements # your function call should look like this: # get_pet_labels(in_arg.dir) # This function creates the results dictionary that contains the results, # this dictionary is returned from the function call as the variable results results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) # TODO 3: Define classify_images function within the file classiy_images.py # Once the classify_images function has been defined replace first 'None' # in the function call with in_arg.dir and replace the last 'None' in the # function call with in_arg.arch Once you have done the replacements your # function call should look like this: # classify_images(in_arg.dir, results, in_arg.arch) # Creates Classifier Labels with classifier function, Compares Labels, # and adds these results to the results dictionary - results classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) # TODO 4: Define adjust_results4_isadog function within the file adjust_results4_isadog.py # Once the adjust_results4_isadog function has been defined replace 'None' # in the function call with in_arg.dogfile Once you have done the # replacements your function call should look like this: # adjust_results4_isadog(results, in_arg.dogfile) # Adjusts the results dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # TODO 5: Define calculates_results_stats function within the file calculates_results_stats.py # This function creates the results statistics dictionary that contains a # summary of the results statistics (this includes counts & percentages). This # dictionary is returned from the function call as the variable results_stats # Calculates results of run and puts statistics in the Results Statistics # Dictionary - called results_stats results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # TODO 6: Define print_results function within the file print_results.py # Once the print_results function has been defined replace 'None' # in the function call with in_arg.arch Once you have done the # replacements your function call should look like this: # print_results(results, results_stats, in_arg.arch, True, True) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, True, True) # TODO 0: Measure total program runtime by collecting end time end_time = time() # TODO 0: Computes overall runtime in seconds & prints it in hh:mm:ss format tot_time = end_time - start_time #calculate difference between end time and start time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60))) print('\n') print('SUMMARY TABLE \n') table_1 = PrettyTable() table_1.field_names = ['Items', 'number'] table_1.add_row(['Total Images', 40]) table_1.add_row(['Dog Images', 30]) table_1.add_row(['Not-a-Dog Images', 10]) print(table_1) print('\n\n') table_2 = PrettyTable() table_2.field_names = [ 'CNN Model Architecture: ', '% of Matches', '% of Correct Dog', '% of Corrects not Dog', '% of Correct Breed', 'Time' ] table_2.add_row(["ResNet", "82.50%", "100.00%", "90.00%", "90.00%", 5]) table_2.add_row(["AlexNet", "75.00%", "100.00%", "100.00%", "80.00%", 3]) table_2.add_row(["VGG", "87.50%", "100.00%", "100.00%", "93.33%", 32]) print(table_2) print('\n') print(' OUT COME\n') print( 'The "best" model architecture is VGG. It out performed both of the other architectures when considering both objectives 1 and 2. \nResNet did classify dog breeds better than AlexNet,\nVGG and AlexNet were able to classify "dogs" and "not-a-dog" at 100% accuracy.\nVGG was the one that was able to classify "dogs" and "not-a-dog" with 100% accuracy and had the best performance regarding breed classification with 93.3% accuracy.' )
# classify images. The only model architectures that this function # will accept are: 'resnet', 'alexnet', and 'vgg'. See the example # usage below. # # Usage: python test_classifier.py -- will run program from commandline # Imports classifier function for using pretrained CNN to classify images from classifier import classifier from get_pet_labels import get_pet_labels from classify_images import classify_images from adjust_results4_isadog import adjust_results4_isadog from calculates_results_stats import calculates_results_stats from print_results import print_results # Defines a dog test image from pet_images folder image_dir = "/Users/abdullahamamun/Downloads/AIPND-revision-master/intropyproject-classify-pet-images/pet_images/" results = get_pet_labels(image_dir) # Defines a model architecture to be used for classification # NOTE: this function only works for model architectures: # 'vgg', 'alexnet', 'resnet' model = "vgg" dogfile = "/Users/abdullahamamun/Downloads/AIPND-revision-master/intropyproject-classify-pet-images/dognames.txt" # Demonstrates classifier() functions usage # NOTE: image_classication is a text string - It contains mixed case(both lower # and upper case letter) image labels that can be separated by commas when a # label has more than one word that can describe it. #image_classification = classifier(image_dir, model) # prints result from running classifier() function #print("\nResults from test_classifier.py\nImage:", image_dir, "using model:",
def main(): # TODO 0: Measures total program runtime by collecting start time start_time = time() in_arg = get_input_args() # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) # TODO 2: Define get_pet_labels function within the file get_pet_labels.py # Once the get_pet_labels function has been defined replace 'None' # in the function call with in_arg.dir Once you have done the replacements # your function call should look like this: # get_pet_labels(in_arg.dir) # This function creates the results dictionary that contains the results, # this dictionary is returned from the function call as the variable results results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) # TODO 3: Define classify_images function within the file classiy_images.py # Once the classify_images function has been defined replace first 'None' # in the function call with in_arg.dir and replace the last 'None' in the # function call with in_arg.arch Once you have done the replacements your # function call should look like this: # classify_images(in_arg.dir, results, in_arg.arch) # Creates Classifier Labels with classifier function, Compares Labels, # and adds these results to the results dictionary - results classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) # TODO 4: Define adjust_results4_isadog function within the file adjust_results4_isadog.py # Once the adjust_results4_isadog function has been defined replace 'None' # in the function call with in_arg.dogfile Once you have done the # replacements your function call should look like this: # adjust_results4_isadog(results, in_arg.dogfile) # Adjusts the results dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # TODO 5: Define calculates_results_stats function within the file calculates_results_stats.py # This function creates the results statistics dictionary that contains a # summary of the results statistics (this includes counts & percentages). This # dictionary is returned from the function call as the variable results_stats # Calculates results of run and puts statistics in the Results Statistics # Dictionary - called results_stats results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # TODO 6: Define print_results function within the file print_results.py # Once the print_results function has been defined replace 'None' # in the function call with in_arg.arch Once you have done the # replacements your function call should look like this: # print_results(results, results_stats, in_arg.arch, True, True) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, True, True) # TODO 0: Measure total program runtime by collecting end time end_time = time() # TODO 0: Computes overall runtime in seconds & prints it in hh:mm:ss format tot_time = end_time - start_time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60))) import pickle with open("results_stats.pickle", "wb") as f: pickle.dump(results_stats, f) print() print() print("***** FINAL RESULTS *****") print() print() print("{} {} {} {} {}".format( "Architecture", "~Dog", "Dog", "Breed", "Label")) print("{}{}{:.2f} {:.2f} {:.2f} {:.2f}".format( in_arg.arch, " " * (19 - len(in_arg.arch)), results_stats['pct_correct_notdogs'], results_stats['pct_correct_dogs'], results_stats['pct_correct_breed'], results_stats['pct_match'])) print() print() print("***************************")
def main(): # TODO 0: Measures total program runtime by collecting start time # start_time from time module at default time start_time = time() # TODO 1: Define get_input_args function within the file get_input_args.py # This function retrieves 3 Command Line Arugments from user as input from # the user running the program from a terminal window. This function returns # the collection of these command line arguments from the function call as # the variable in_arg #read command line args in_arg = get_input_args() # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) # TODO 2: Define get_pet_labels function within the file get_pet_labels.py # Once the get_pet_labels function has been defined replace 'None' # in the function call with in_arg.dir Once you have done the replacements # your function call should look like this: # get_pet_labels(in_arg.dir) # This function creates the results dictionary that contains the results, # this dictionary is returned from the function call as the variable results # This function creates the results dictionary that contains the results, results = get_pet_labels(in_arg.dir) print(results) # Function that checks Pet Images in the results Dictionary using results # Prints first 10 key-value pairs check_creating_pet_image_labels(results) # TODO 3: Define classify_images function within the file classiy_images.py # Once the classify_images function has been defined replace first 'None' # in the function call with in_arg.dir and replace the last 'None' in the # function call with in_arg.arch Once you have done the replacements your # function call should look like this: # classify_images(in_arg.dir, results, in_arg.arch) # Creates Classifier Labels with classifier function, Compares Labels, # and adds these results to the results dictionary - results classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) # TODO 4: Define adjust_results4_isadog function within the file adjust_results4_isadog.py # Once the adjust_results4_isadog function has been defined replace 'None' # in the function call with in_arg.dogfile Once you have done the # replacements your function call should look like this: # adjust_results4_isadog(results, in_arg.dogfile) # Adjusts the results dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # TODO 5: Define calculates_results_stats function within the file calculates_results_stats.py # This function creates the results statistics dictionary that contains a # summary of the results statistics (this includes counts & percentages). This # dictionary is returned from the function call as the variable results_stats # Calculates results of run and puts statistics in the Results Statistics # Dictionary - called results_stats results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # TODO 6: Define print_results function within the file print_results.py # Once the print_results function has been defined replace 'None' # in the function call with in_arg.arch Once you have done the # replacements your function call should look like this: # print_results(results, results_stats, in_arg.arch, True, True) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, True, True) # TODO 0: Measure total program runtime by collecting end time end_time = end_time = time() # TODO 0: Computes overall runtime in seconds & prints it in hh:mm:ss format tot_time = end_time - start_time #calculate difference between end time and start time print( "\n** Total Elapsed Runtime:", str(int((tot_time / 3600))) + ":" + str(int( (tot_time % 3600) / 60)) + ":" + str(int((tot_time % 3600) % 60))) tableA = [["# Total Images", 40], ["# Dog Images", 30], ["# Not-a-Dog Images", 10]] headers = ["", ""] print(tabulate(tableA, headers, tablefmt="grid")) print("\n\n\n") tableB = [["ResNet", "90%", "100%", "90%", "82.5%", 6], ["AlexNet", "100%", "100%", "80%", "75%", 3], ["VGG", "100%", "100%", "93.3%", "87.5%", 35]] headers = [ "CNN Model Architecture: ", "% Not-a-Dog Correct", "% Dogs Corrects", "% Breeds Correct", "% Match Labels", "Runtime (seconds)" ] print(tabulate(tableB, headers, tablefmt="grid")) print( "Given our results, the best model architecture is VGG,The model VGG was the one that was able to classify 'dogs' and 'not-a-dog' with 100% accuracy and had the best performance regarding breed classification with 93.3% accuracy. The Model AlexNet was the most efficient with the fastest runtime at only 3 seconds but still images 100% accuracy for identifying dogs correctly" )
def main(): # TODO 0: Measures total program runtime by collecting start time start_time = time() # for i in range(0,5): # sleep(1) # TODO 1: Define get_input_args function within the file get_input_args.py # This function retrieves 3 Command Line Arugments from user as input from # the user running the program from a terminal window. This function returns # the collection of these command line arguments from the function call as # the variable in_arg in_arg = get_input_args() # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) # TODO 2: Define get_pet_labels function within the file get_pet_labels.py # Once the get_pet_labels function has been defined replace 'None' # in the function call with in_arg.dir Once you have done the replacements # your function call should look like this: # get_pet_labels(in_arg.dir) # This function creates the results dictionary that contains the results, # this dictionary is returned from the function call as the variable results results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) # TODO 3: Define classify_images function within the file classiy_images.py # Once the classify_images function has been defined replace first 'None' # in the function call with in_arg.dir and replace the last 'None' in the # function call with in_arg.arch Once you have done the replacements your # function call should look like this: # classify_images(in_arg.dir, results, in_arg.arch) # Creates Classifier Labels with classifier function, Compares Labels, # and adds these results to the results dictionary - results classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) # TODO 4: Define adjust_results4_isadog function within the file adjust_results4_isadog.py # Once the adjust_results4_isadog function has been defined replace 'None' # in the function call with in_arg.dogfile Once you have done the # replacements your function call should look like this: # adjust_results4_isadog(results, in_arg.dogfile) # Adjusts the results dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # TODO 5: Define calculates_results_stats function within the file calculates_results_stats.py # This function creates the results statistics dictionary that contains a # summary of the results statistics (this includes counts & percentages). This # dictionary is returned from the function call as the variable results_stats # Calculates results of run and puts statistics in the Results Statistics # Dictionary - called results_stats results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # TODO 6: Define print_results function within the file print_results.py # Once the print_results function has been defined replace 'None' # in the function call with in_arg.arch Once you have done the # replacements your function call should look like this: # print_results(results, results_stats, in_arg.arch, True, True) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, True, True) # TODO 0: Measure total program runtime by collecting end time end_time = time() # TODO 0: Computes overall runtime in seconds & prints it in hh:mm:ss format tot_time = end_time - start_time print("\n** Total Elapsed Runtime:", str(int((tot_time/3600)))+":"+str(int((tot_time%3600)/60))+":" +str(int((tot_time%3600)%60)) )
def main(): # Measures total program runtime by collecting start time start_time = time() in_arg = get_input_args() print("Command Line Arguments:\n dir =", in_arg.dir, "\n arch =", in_arg.arch, "\n dogfile =", in_arg.dogfile) # Function that checks command line arguments using in_arg check_command_line_arguments(in_arg) results = get_pet_labels(in_arg.dir) # Function that checks Pet Images in the results Dictionary using results check_creating_pet_image_labels(results) classify_images(in_arg.dir, results, in_arg.arch) # Function that checks Results Dictionary using results check_classifying_images(results) # TODO 4: Define adjust_results4_isadog function within the file adjust_results4_isadog.py # Once the adjust_results4_isadog function has been defined replace 'None' # in the function call with in_arg.dogfile Once you have done the # replacements your function call should look like this: # adjust_results4_isadog(results, in_arg.dogfile) # Adjusts the results dictionary to determine if classifier correctly # classified images as 'a dog' or 'not a dog'. This demonstrates if # model can correctly classify dog images as dogs (regardless of breed) adjust_results4_isadog(results, in_arg.dogfile) # Function that checks Results Dictionary for is-a-dog adjustment using results check_classifying_labels_as_dogs(results) # TODO 5: Define calculates_results_stats function within the file calculates_results_stats.py # This function creates the results statistics dictionary that contains a # summary of the results statistics (this includes counts & percentages). This # dictionary is returned from the function call as the variable results_stats # Calculates results of run and puts statistics in the Results Statistics # Dictionary - called results_stats results_stats = calculates_results_stats(results) # Function that checks Results Statistics Dictionary using results_stats check_calculating_results(results, results_stats) # TODO 6: Define print_results function within the file print_results.py # Once the print_results function has been defined replace 'None' # in the function call with in_arg.arch Once you have done the # replacements your function call should look like this: # print_results(results, results_stats, in_arg.arch, True, True) # Prints summary results, incorrect classifications of dogs (if requested) # and incorrectly classified breeds (if requested) print_results(results, results_stats, in_arg.arch, True, True) #Check Time to code #sleep(10) # TODO 0: Measure total program runtime by collecting end time end_time = time() # TODO 0: Computes overall runtime in seconds & prints it in hh:mm:ss format tot_time = end_time - start_time #calculate difference between end time and start time print("\n** Total Elapsed Runtime:", str(int((tot_time/3600)))+":"+str(int((tot_time%3600)/60))+":" +str(int((tot_time%3600)%60)) )