Пример #1
0
def images_motivation(dnn_daemon):
    """
    Plots the images from the motivation section
    """
   # The image numbers of our motivation images
    img_nums = img_num_motivation

    # Initialise an image generator
    img_dir = 'images/val/images/'
    img_class_map_file = 'images/val/val.txt'
    class_file = 'images/val/synset_words.txt'
    image_generator = ImageGenerator(img_dir, img_class_map_file, class_file)

    # Get a path and label for each of our images
    img_paths = list()
    img_labels = list()
    for img in img_nums:
        path, label = image_generator.get_image_data(img)
        img_paths.append(path)
        img_labels.append(label)

    return img_paths
Пример #2
0
def inference(dnn_daemon, img_nums, model_names, n_img_to_infer=5):
    """
    Allows to do inference using a list of images and models.
    """
    
    # Check all models are available
    for model in model_names:
        if not model_available(dnn_daemon, model):
            print("ERROR: Model", model, "not availale. Exiting.")
            sys.exit()

    # Initialise an image generator
    img_dir = 'images/val/images/'
    img_class_map_file = 'images/val/val.txt'
    class_file = 'images/val/synset_words.txt'
    image_generator = ImageGenerator(img_dir, img_class_map_file, class_file)

    # Get a path and label for each of our images
    img_paths = list()
    img_labels = list()
    for img in img_nums:
        path, label = image_generator.get_image_data(img)
        img_paths.append(path)
        img_labels.append(label)

    # Infer each image with each model, get the results
    # results: dict, mapping (img_num, model) to (inference_times, prediciton)
    print("Running inference on Jetson...")
    img_model_to_results = dict()
    img_model_to_img = []
    img_model_to_models = []
    img_model_to_inference = []
    img_model_to_prediction = []
    img_model_to_results = []
    
    if(len(model_names) is 0):
        print("Any model was selected!!!")
        return img_model_to_img, img_model_to_models, img_model_to_results
    
    percentage_of_each_execution=100/(len(img_paths)*len(model_names))
    counter=0
    first_time=0
    for img_num, path in enumerate(img_paths):
        img_model_to_inference = []
        img_model_to_img.append("Image " + `img_num`)
        for model in model_names:
            results = dnn_daemon.inference(model, [path], 1)
            inference_time, prediction_vals, prediction_classes = results
            inference_time = inference_time[0]
            ordered_prediction = convert_prediction(prediction_vals[0],
                                                    prediction_classes[0],
                                                    image_generator.class_names)
            #img_model_to_results[(img_num, model)] = (inference_time, ordered_prediction)
            
            if first_time is 0:
                img_model_to_models.append(model)
                
            img_model_to_inference.append(inference_time)
            #img_model_to_prediction.append(ordered_prediction)
            counter=counter+1
            print(percentage_of_each_execution*counter, "%\n")
            
        img_model_to_results.append(img_model_to_inference)
        first_time=first_time+1
        
    #print("All the images has been inferenced! ")
    return img_model_to_img, img_model_to_models, img_model_to_results