print(key + ":", param_dict[key]) result_file.write(key + ": " + param_dict[key] + '\n') #param_dict['dataset_name'] = "d:/b3sd" # Get parameters from training parameters network_type = param_dict['network_type'] dataset_name = param_dict['dataset_name'] data_specifier = param_dict['data_specifier'] #channels = [int(c) for c in param_dict['channels'].split(",")] sec1_frame = tpu.str2bool(param_dict['sec1_frame']) # Read filenames for dataset to use X,Y = gf.get_filenames(dataset_name, data_specifier, "test") print(X.shape) print(Y.shape) # Prepare input and output name of model, # then make model and load weights from training # Weights are saved before and efter to validate succesful load input_names, output_name, stream = tu.prepare_stream(network_type) model = tu.make_network_model(param_dict,stream,None) weights_pre = model.get_weights() model = tu.load_weights(model, param_dict, stream, False, "test") weights_after = model.get_weights() weight_names = [weight.name for layer in model.layers for weight in layer.weights] tu.check_weights(weights_pre, weights_after, weight_names)
def main(argv): inputfile, outputfile = get_filenames(argv) spell_check(inputfile, outputfile) return
# Reads variables specified in the terminal and places them # in a dictionary, param_dict param_dict = {} for i in sys.argv[1:]: variable, value = i.split("=") param_dict[variable] = value # Write parameters to output file given amongst parameters tu.save_parameters(param_dict) # Read filenames for dataset to use dataset_name = param_dict['dataset_name'] data_specifier = param_dict['data_specifier'] X,Y = gf.get_filenames(dataset_name,data_specifier,"train") X_val,Y_val = gf.get_filenames(dataset_name,data_specifier,"val") # Get distribution of classes, potentially to be used in training class_distribution = tu.get_class_distribution(Y) # Read some parameters needed for training savefile_name = param_dict['savefile_name'] optimizer_type = param_dict['optimizer'] current_lr = float(param_dict['initial_learning_rate']) # Prepare input and output name of model, # then make model and load initial weights
def main(): # Let's import first frame of videofile, and show it print('Choose videofile for making calib curves') file = get_filenames() file = file[0] # get just single file instead of list print('Importing file ', file) frame = skvideo.io.vread(file, num_frames=1) # import just first frame frame = rgb2gray(frame[0]) # get element instead of list, make grayscale # plt.figure() # plt.imshow(frame, cmap=plt.cm.gray) # plt.show() # Compensate angle if its needed finish = False angle = 0 while finish == False: angle, finish = rotate_image(frame, angle) if angle != 0: frame = rotate(frame, angle) # Detect center of lightspot, show quadrants: centroid = threshold_centroid(frame) print('Showing first frame of video with quadrants...') plot_im_w_quadrants(frame, centroid, fig_title='1st frame with quadrants') # Demonstrate how shifted image looks like print('Image shifted for 5px in each axis will look like this:') transform = AffineTransform(translation=(5, 5)) shifted = warp(frame, transform, mode='constant', preserve_range=True) plot_im_w_quadrants(shifted, centroid, fig_title='5 px shift') print( 'If you want to have max test shift as shown above, just press enter') print( '(If lightspot is partially out of field of view, better to choose smaller shift)' ) print( 'Otherwise manually enter desired shift of image in px, and press enter' ) print('Note: the same shift will be used for each axis') max_shift = input() if max_shift == '': max_shift = 5 else: max_shift = float(max_shift) print('Images will be shifted from 0 to %s px' % max_shift) k_px_um = input('Enter px to um coefficient (scale):\n') k_px_um = float(k_px_um) # Shift images along x axis shifted_im = [] # specify parameters for calculations # generate dx value for linear shift # x_shift = np.array([0.1*dx for dx in range(0, max_shift+1)]) dx = 0.1 x_shift = np.arange(0, max_shift * (1 + dx), dx * max_shift) # k_px_um = 1.36 # scale px to um normalization = False # don't scale signal over SUM shift_vs_sig = True # calculate shift from signal, not other way for dx in x_shift: transform = AffineTransform(translation=(dx, dx)) # shift along both axis shifted_im.append( warp(frame, transform, mode='constant', preserve_range=True)) # Calculate the intensities Il = np.array([]) Iz = np.array([]) Isum = np.array([]) for i in range(len(shifted_im)): Iz, Il, Isum = calc_intensities(shifted_im[i], centroid, Iz, Il, Isum) # Show calculated intensity difference vs displacement and get linear fit coefficients of the calibration: # without normalization plot_shift_curves(k_px_um=k_px_um, Il=Il, Iz=Iz, Isum=Isum, x_shift=x_shift, normalization=False, shift_vs_sig=shift_vs_sig) k_x, b_x, k_y, b_y = calc_calib_line(x_shift=x_shift, y_shift=x_shift, k_px_um=k_px_um, Il=Il, Iz=Iz, normalization=False, shift_vs_sig=shift_vs_sig) # with normalization plot_shift_curves(k_px_um=k_px_um, Il=Il, Iz=Iz, Isum=Isum, x_shift=x_shift, normalization=True, shift_vs_sig=shift_vs_sig) k_x_norm, b_x_norm, k_y_norm, b_y_norm = calc_calib_line( x_shift=x_shift, y_shift=x_shift, k_px_um=k_px_um, Il=Il, Iz=Iz, Isum=Isum, normalization=True, shift_vs_sig=shift_vs_sig) return k_x, b_x, k_y, b_y, k_x_norm, b_x_norm, k_y_norm, b_y_norm
return exp_dir_path def export_cleaned_data(data, path, in_fname, out_fname, fps): data = pd.concat([data, pd.DataFrame({'fps': [fps]})], axis=1) output_name = in_fname + '_' + out_fname + '.csv' data.to_csv(os.path.join(path, output_name)) print('Exported %s file' % output_name) def export_fig(path, in_fname, out_fname): output_name = in_fname + '_' + out_fname + '.png' plt.savefig(output_name) file_list = get_filenames() for file in file_list: df = pd.read_csv(file) fps = get_fps_from_fname(file) print('Read file %s recorded with %s fps...' % (os.path.basename(file), fps)) y = df['Iz'] x = df['Il'] y_norm = df['Iz norm'] x_norm = df['Il norm'] t = df['t'] dt = df['t'].loc[1] - df['t'].loc[0] x_fit, x_flat = flattening(data=x, dt=dt, chunk_l=60) x_norm_fit, x_norm_flat = flattening(data=x_norm, dt=dt, chunk_l=60) y_fit, y_flat = flattening(data=y, dt=dt, chunk_l=60) y_norm_fit, y_norm_flat = flattening(data=y_norm, dt=dt, chunk_l=60)
# Get parameters from training parameters network_type2 = param_dict_part1['network_type'] dataset_name2 = param_dict_part1['dataset_name'] print(dataset_name2) data_specifier2 = param_dict_part1['data_specifier'] sec1_frame2 = tpu.str2bool(param_dict_part1['sec1_frame']) # Get parameters from training parameters network_type4 = param_dict_part2['network_type'] dataset_name4 = param_dict_part2['dataset_name'] data_specifier4 = param_dict_part2['data_specifier'] sec1_frame4 = tpu.str2bool(param_dict_part2['sec1_frame']) # Read filenames for dataset to use X2,Y2 = gf.get_filenames("b3sd", "2_classes", "test") #dataset = gf.b3sd_sample(int(data_specifier[0]), "test", "") #dataset = gf.ucf_sample(int(data_specifier[4]), "test") #dataset = gf.b3sd_local_sample(param_dict, "test") print(X2.shape) print(Y2.shape) # Prepare input and output name of model, # then make model and load weights from training # Weights are saved before and efter to validate succesful load input_part1, op1, stream_part1 = tu.prepare_stream(network_type2) model_part1 = tu.make_network_model(param_dict_part1,stream_part1,None) weights_pre = model_part1.get_weights() model_part1 = tu.load_weights(model_part1, param_dict_part1, stream_part1, True, "test")