Beispiel #1
0
def cross_ref_replace_dict(t_file_name):
    #This function creates the cross reference dictionary used by
    #insert_mods_into_js_file
    import pandas as pd
    from digit_capture import set_file_name_prefix
    from digit_capture import get_global_settings as gs
    colab_choice_save=['not_colab_output(imgData)','colab_output(imgData)']
    colab_choice_label=['change_class_label_no_colab()',
                        'change_class_label_colab()']
    t_full_side_size=gs('grid_count')*gs('pxl')
    cross_ref_dict={'?width?':t_full_side_size,'?height?':t_full_side_size}
    test_keys = ["?class00?",
                 "?class01?",
                 "?class02?",
                 "?class03?",
                 "?class04?",
                 "?class05?",
                 "?class06?",
                 "?class07?",
                 "?class08?",
                 "?class09?",
                 "?selval?",
                 "?width?",
                 "?height?"]
    test_values = [0,0,0,0,0,0,0,0,0,0,3,t_full_side_size,t_full_side_size] 
    # using dictionary comprehension 
    # to convert lists to dictionary 
    res = {test_keys[i]: test_values[i] for i in range(len(test_keys))}
    res['?selval?']=get_val_from_dict_csv('?selval?')
    #fname_pfx=set_file_name_prefix(0)[0]
    #print(fname_pfx)
    #df=pd.read_csv(fname_pfx+t_file_name,header=None)
    #t_df=df.iloc[:,0:2]
    #t_list=['class','replace_dict']
    #t_df.columns = t_list
    #dd=t_df.groupby('class').count().to_dict()
    dd=get_class_counts(t_file_name)
    #print(dd['replace_dict'])
    for k, v in dd['replace_dict'].items():
        #print(k,dd['replace_dict'][k])
        res[k]=dd['replace_dict'][k]
    res['?grid_count?']=get_dict()['grid_count']
    res['?pxl?']=get_dict()['pxl']
    res['?line_wd?']=get_dict()['line_wd']
    res['?output_data?']=colab_choice_save[in_colab()]
    res['?class_label_choice?']=colab_choice_label[in_colab()]
    return res
Beispiel #2
0
def get_val_from_dict_csv(t_key):
    #input is a key. That is the row entry key in the dictionary_inputs.csv file.
    #Read the file into pandas. Convert the Name column into a list. Find the
    #index where the lest entry = the_key. Use the index to get the value
    #from a list made from th Value column in the file. Return the value as
    #a string
    import pandas as pd
    t_prefix=set_file_name_prefix(in_colab())[0]
    t_file=t_prefix+'dictionary_inputs.csv'
    df=pd.read_csv(t_file)
    t_list_n=list(df['Name'])
    t_pos=t_list_n.index(t_key)
    t_list_v=list(df['Value'])
    return str(t_list_v[t_pos])
Beispiel #3
0
def set_file_name_prefix(colab):
    # Gets pathname etc based on there it is run.
    # if colab=1, set up structure for colab.
    # if colab=0, set up structure for local.
    # if colab=2, set up structure when in /content/drive  
    import sys
    import os
    t_prefix=""
    t_path=""
    if(in_colab()==1):
        colab=1
    if(colab==1):
        t_path='/content/drive/My Drive/Colab Notebooks/digit_data_entry/digit_data_entry'
        t_prefix=t_path+"/"
    else:
        if(colab==0):
            t_prefix="/content/drive"
        st=os.getcwd()    
        t_path=st+"/"+t_prefix
        t_prefix=t_path+"/"
    return (t_prefix,t_path)    
Beispiel #4
0
def update_class_number(nw_class_index):
    #reads in dictionary_inputs.csv which holds values for global
    #variable where the name is the global variable name. Once read in,
    #it updates class label. This needs to be done via user so it can be changed
    #as a user enters different digit classes. 
    import pandas as pd
    t_list02=[]
    for i in range(0,10):
        t_class='?class0'+str(i)+'?'
        t_list02.append(t_class)
    nw_class=t_list02[nw_class_index]    
    t_prefix=set_file_name_prefix(in_colab())[0]
    t_file=t_prefix+'dictionary_inputs.csv'
    df=pd.read_csv(t_file)
    t_list=list(df['Name'])
    t_pos=t_list.index('t_class')
    df.at[t_pos, 'Value']=nw_class
    t_pos=t_list.index('?selval?')
    df.at[t_pos, 'Value']=nw_class_index
    df.to_csv(t_file,index=False)
    return df
Beispiel #5
0
def mount_drive():
    #Used to mount google drive when run in colab
    if(not in_colab()):
        return
    from google.colab import drive
    drive.mount('/content/drive')