utility_functions.py
def compile_results(top_p, top_class, name_mapping):
    
    ''' 
    Function compiles the probabilities from an image inference model with the 
    corresponding image classes and returns a dictionary with the image classes as 
    keys and the probabilities as values.
        
    Parameters:
     probabilities - tuple consisting of two torch tensors (from function predict()), 
                     first  tensor: index for class mapping, 
                     second tensor: probability calculated by model
     name_mapping  - dictionary with idices as keys and corresponding class names
                     as values.

    Returns:
     results_dic   - dictionary with the image classes as keys and the 
                     probabilities as values
    '''
    
    ## Get probabilities and convert to list
    p = top_p[0].cpu().numpy().tolist()
    
    ## Create list with indices which can then be mapped to the corresponding names
    keys = top_class[0].cpu().numpy().tolist()
    
    ## Create a list with class names:
    
    # Interate thru dictionary 'name_mapping using the keys to get corresponding 
    # class names
    class_names = get_class_name(keys, name_mapping)
 
    ## Create results dictionary:
    
    # Initialize empty dictionary for the resultes   
    results_dic = dict()
    
    # Create dictionary entries
    for i in range(len(class_names)):
        if class_names[i] not in results_dic:
            results_dic[class_names[i]] =  float(p[i]) # convert probabilit 
    
    print('Indices: ', keys)
    #print(p)       
    # print(class_names)
    print('result dictionary :', results_dic)

    ## Return the results dictionary
    return results_dic, keys
 
    Function compiles the probabilities from an image inference model with the 
    corresponding image classes and returns a dictionary with the image classes as 
    keys and the probabilities as values.
        
    Parameters:
     probabilities - tuple consisting of two torch tensors (from function predict()), 
                     first  tensor: index for class mapping, 
                     second tensor: probability calculated by model
     name_mapping  - dictionary with idices as keys and corresponding class names
                     as values.

    Returns:
     results_dic   - dictionary with the image classes as keys and the 
                     probabilities as values
    
Function compiles the probabilities from an image inference model with the
corresponding image classes and returns a dictionary with the image classes as
keys and the probabilities as values.

tuple consisting of two torch tensors (from function predict()),
first  tensor: index for class mapping,
second tensor: probability calculated by model
name_mapping  - dictionary with idices as keys and corresponding class names
as values.

results_dic   - dictionary with the image classes as keys and the
probabilities as values
Function compiles the probabilities from an image inference model with the corresponding image classes and returns a dictionary with the image classes as keys and the probabilities as values . tuple consisting of two torch tensors ( from function predict () ) first tensor : index for class mapping second tensor : probability calculated by model name_mapping - dictionary with idices as keys and corresponding class names as values . results_dic - dictionary with the image classes as keys and the probabilities as values
def compile_results(top_p, top_class, name_mapping):
    p = top_p[0].cpu().numpy().tolist()
    keys = top_class[0].cpu().numpy().tolist()
    class_names = get_class_name(keys, name_mapping)
    results_dic = dict()
    for i in range(len(class_names)):
        if class_names[i] not in results_dic:
            results_dic[class_names[i]] =  float(p[i]) 
    print('Indices: ', keys)
    print('result dictionary :', results_dic)
    return results_dic, keys
def compile_results ( top_p , top_class , name_mapping ) : p = top_p [ 0 ] . cpu ( ) . numpy ( ) . tolist ( ) keys = top_class [ 0 ] . cpu ( ) . numpy ( ) . tolist ( ) class_names = get_class_name ( keys , name_mapping ) results_dic = dict ( ) for i in range ( len ( class_names ) ) : if class_names [ i ] not in results_dic : results_dic [ class_names [ i ] ] = float ( p [ i ] ) print ( 'Indices: ' , keys ) print ( 'result dictionary :' , results_dic ) return results_dic , keys
Function compiles the probabilities from an image inference model with the
corresponding image classes and returns a dictionary with the image classes as
keys and the probabilities as values.
Function compiles the probabilities from an image inference model with the corresponding image classes and returns a dictionary with the image classes as keys and the probabilities as values .
''' 
    Function compiles the probabilities from an image inference model with the 
    corresponding image classes and returns a dictionary with the image classes as 
    keys and the probabilities as values.
        
    Parameters:
     probabilities - tuple consisting of two torch tensors (from function predict()), 
                     first  tensor: index for class mapping, 
                     second tensor: probability calculated by model
     name_mapping  - dictionary with idices as keys and corresponding class names
                     as values.

    Returns:
     results_dic   - dictionary with the image classes as keys and the 
                     probabilities as values
    ''' ## Get probabilities and convert to list ## Create list with indices which can then be mapped to the corresponding names ## Create a list with class names: # Interate thru dictionary 'name_mapping using the keys to get corresponding  # class names ## Create results dictionary: # Initialize empty dictionary for the resultes    # Create dictionary entries # convert probabilit  #print(p)        # print(class_names) ## Return the results dictionary
top_p
top_class
name_mapping