def generate_data(path): corrupted = ['indooPool_Inside_gif.jpg'] # file with 10 folders file_list = get_path_list(path) for i in range(0 , len(file_list) , 1): # i is a label # specific file of the 10 class_name = file_list[i] class_path = os.path.join(path , class_name) # images paths in 1 folder of the 10 folders class_path_list = get_path_list(class_path) # iterate throw the images of 1 class for j in range(0 , len(class_path_list) , 1): img_name = class_path_list[j] final_path = os.path.join(class_path ,img_name) # corrupted images if class_path_list[j] in corrupted: continue img = cv2.imread(final_path, -1) # bad image if check_image(img) == 0: continue # preprocess the img , then agument the img , then save it in the new file pimg = preprocessing(img) img_l = Agumentation(pimg) label = i # save the image save_new_imgs(img_l , img_name , class_name) return
def test_img(img,split_comb,flag): alpha = 0.5 red = (0,0,255) green = (0,128,0) yellow = (0,255,255) orange = (0,255,165) image = cv2.imread(img) grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) p_image = preprocessing(grey) n_row,n_col = split_comb instance = splitter(p_image,n_row,n_col) new_im = [] for i in range(len(flag)): backtorgb = cv2.cvtColor(instance[i],cv2.COLOR_GRAY2RGB) overlay = backtorgb.copy() output = backtorgb.copy() if flag[i] <= 1: cv2.rectangle(overlay, (0, 0), (174, 64), red, -1) elif flag[i] == 2: cv2.rectangle(overlay, (0, 0), (174, 64), orange, -1) elif flag[i] == 3: cv2.rectangle(overlay, (0, 0), (174, 64), yellow, -1) else: cv2.rectangle(overlay, (0, 0), (174, 64), green, -1) cv2.addWeighted(overlay, alpha, output, 1 - alpha, 0, output) outputImage = cv2.copyMakeBorder(output,1,1,1,1,cv2.BORDER_CONSTANT,value=(0,0,0)) new_im.append(outputImage) out_im = np.concatenate([np.concatenate(new_im[(i*n_col):((i+1)*n_col)],axis=1) for i in range(n_row)],axis=0) return(out_im)
def feature(file, split=None): image = cv2.imread(file) grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) p_image = preprocessing(grey) if split != None: instance = splitter(p_image, split[0], split[1]) features = pd.DataFrame([ all_features(np.array(inst), np.array(inst)) for inst in instance ]) features.index = [ os.path.basename(file).replace('.png', '') + '_' + str(k) for k in range(1, split[0] * split[1] + 1) ] else: features = pd.DataFrame( [all_features(np.array(p_image), np.array(p_image))]) features.index = [os.path.basename(file).replace('.png', '')] return (features)
def multi_user_add(src_path, out_path): #Reading all images from source Path cust = {} for i in src_path: j = os.path.basename(i).rsplit('_', 1)[0] if j not in cust: cust[j] = [] cust[j].append(i) cnt = 0 replaced = 0 drop = 0 for cust_id in cust: if len(cust[cust_id]) < 4: drop = drop + 1 continue if os.path.isdir(os.path.join(out_path, cust_id)): replaced = replaced + 1 shutil.rmtree(os.path.join(out_path, cust_id)) os.mkdir(os.path.join(out_path, cust_id)) os.mkdir(os.path.join(out_path, cust_id, "original")) os.mkdir(os.path.join(out_path, cust_id, "processed")) for i in range(len(cust[cust_id])): shutil.copy( cust[cust_id][i], os.path.join(out_path, cust_id, "original", str(i + 1).zfill(2) + ".png")) image = cv2.imread(cust[cust_id][i]) grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) p_image = preprocessing(grey) cv2.imwrite( os.path.join(out_path, cust_id, "processed", str(i + 1).zfill(2) + ".png"), p_image) train_files(out_path, cust_id) cnt = cnt + 1 return ([cnt - replaced, replaced, drop])
def main(): print("test main function ") obj = preprocessing(test_string) input = obj.lowercasing(input_string) print("lower case word is {}".format(input)) stop_input = obj.stopwordemoval(input) print("stop result is {}".format(stop_input)) utli_obj = utility() print(utli_obj.get_path(folder_path)) path = utli_obj.get_path(folder_path) print(utli_obj.get_file_list(path)) class_folder = utli_obj.get_file_list(path) count = 0 class_count = 0 data = [] for folder in utli_obj.get_file_list(path): print("folder name's are {} \n".format(folder)) #print("list of file is {}".format(utli_obj.get_file_list(os.path.join(path,folder)))) for file in utli_obj.get_file_list(os.path.join(path, folder)): print("print fil ein folder is {}".format(file)) #utility=utility() file_f = utli_obj.file_open( os.path.join(os.path.join(path, folder), file)) data.append(utli_obj.read_file(file_f)) print("data in file is {}".format(data)) count += 1 if count == 5: break #class_folder[class_count]=folder utli_obj.write_csv_file(data, class_folder)
def single_user_add(img_paths, out_path, cust_id=""): if not (isinstance(img_paths, list) or isinstance(img_paths, tuple)): return ("Error") if len(img_paths) < 4: return ("Select atleast 4 Signatures") if cust_id == "": cust_id = "new_user" i = 1 while cust_id in os.listdir(out_path): cust_id = "new_user_" + str(i).zfill(2) i = i + 1 del i if os.path.isdir(os.path.join(out_path, cust_id)): shutil.rmtree(os.path.join(out_path, cust_id)) os.mkdir(os.path.join(out_path, cust_id)) os.mkdir(os.path.join(out_path, cust_id, "original")) os.mkdir(os.path.join(out_path, cust_id, "processed")) for i in range(len(img_paths)): shutil.copy( img_paths[i], os.path.join(out_path, cust_id, "original", str(i + 1).zfill(2) + ".png")) image = cv2.imread(img_paths[i]) grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) p_image = preprocessing(grey) cv2.imwrite( os.path.join(out_path, cust_id, "processed", str(i + 1).zfill(2) + ".png"), p_image) train_files(out_path, cust_id) return (cust_id)
def batch_preproc(test): dfs_lst = [] for i in tqdm(range(0, len(test))): test_file = test[i] # Verify that test file is in the directory if test_file in files: print('File is in there') else: print('Trouble finding ' + str(test_file)) continue test_path = os.path.join(abfs, test_file) try: df_p = preprocessing(test_path, plot=False) except: print('Problem with ' + test_file) continue df_p['Original File'] = test_file dfs_lst.append(df_p) dff = pd.concat(dfs_lst) return dff
series_mean = series_array.mean(axis=1).reshape(-1, 1) series_array = series_array - series_mean series_array = series_array.reshape( (series_array.shape[0], series_array.shape[1], 1)) return series_array, series_mean def transform_series_decode(series_array, encode_series_mean): series_array = np.log1p(np.nan_to_num(series_array)) # filling NaN with 0 series_array = series_array - encode_series_mean series_array = series_array.reshape( (series_array.shape[0], series_array.shape[1], 1)) return series_array series_array, data_start_date, data_end_date, train_pred_start, train_pred_end, train_enc_start, \ train_enc_end, val_enc_start, val_enc_end, date_to_index = preprocessing() #### Build the model #### latent_dim = 50 # LSTM hidden units dropout = .20 # Define an input series and encode it with an LSTM. encoder_inputs = Input(shape=(None, 1)) encoder = LSTM(latent_dim, dropout=dropout, return_state=True) encoder_outputs, state_h, state_c = encoder(encoder_inputs) # We discard `encoder_outputs` and only keep the final states. These represent the "context" # vector that we use as the basis for decoding. encoder_states = [state_h, state_c] # Set up the decoder, using `encoder_states` as initial state.
import os from utility import utility import pandas as pd from model import Sentimentmodel from sklearn.model_selection import train_test_split import numpy as np import matplotlib.pyplot as plt from sklearn.preprocessing import OneHotEncoder folder_path="tokens" class_folder=[] batchsize=8 epoch=2 vsplit=0.2 verbose=0.2 preprocessing_obj= preprocessing() ytrain=[1,2,3,4,5,1,2,0,2,2] def pre_process(input): #X_t=preprocessing_obj.tokenization(input) #X_train=preprocessing_obj.stopwordemoval(input) #X_t=preprocessing_obj.lowercasing(X_train) #print("X_train is {}".format(X_t)) pre_process_val=preprocessing_obj.bagofwords(input) print("Bag of words for this {}".format(len(pre_process_val))) f = open("bagofword.txt", "a") f.write((str(pre_process_val[:100]))) f.close() return pre_process_val