def local(path='', num_train=None, num_validation=None, num_classes=2, augment=True): trainpath = path + 'train/*' validationpath = path + 'validation/*' print("Reading training from {0}".format(trainpath)) files = glob.glob(trainpath) files = files if num_train is None else files[:num_train] df = func.toDF_all(files, reb=False) X_train, y_train = func.split(df, categories=num_classes, augment_data=augment) X_train = X_train / 255 print('X train shape', X_train.shape) print('y train shape', y_train.shape) print("Reading validation from {0}".format(validationpath)) files = glob.glob(validationpath) files = files if num_validation is None else files[:num_validation] df = func.toDF_all(files, reb=False) X_validation, y_validation = func.split(df, categories=num_classes, augment_data=augment) X_validation = X_validation / 255 print('X validation shape', X_validation.shape) print('y validation shape', y_validation.shape) return X_train, y_train, X_validation, y_validation
def upload_page(): if request.method == "GET": return render_template("index.html") else: uploaded_file = request.files['file'] if uploaded_file != '': print(os.getcwd()) arq = os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(uploaded_file.filename)) print(arq) uploaded_file.save(arq) name= request.form["name"] page = int(request.form["page"]) id = request.form["id"] quest = "" for i in range(1,MAX_ITENS+1): key = "customRadioInline"+str(i) try: quest += request.form[key] except KeyError: quest += "." output = os.path.join(app.config['UPLOAD_FOLDER'], "Gabarito_"+"_".join(name.split())) split(arq, page, output+".pdf") transform(id,quest,output,name,parameters) return send_file(output+".pdf",as_attachment =True)#,mimetype = '.pdf') os.remove(output+".pdf") os.remove(arq)
def test_iris_split(): x = iris.data[:,0] y = iris.target split_vals = feature_splits(x, y) max_gain = -1 best_split = None for split_val in split_vals: splits = split(x, y, split_val) gain = gini_gain(y, splits) if gain > max_gain: max_gain = gain best_split = split_val best_l = np.array(splits[0]) best_r = np.array(splits[1]) print "-------IRIS DATA TEST -----------" print"\n" print "Best split value was: {} for a gini_gain of {}".format(best_split, max_gain) print "\n" l = distribution_from_array(best_l) r = distribution_from_array(best_r) print "left leaf count: {}".format(len(best_l)) print best_l print l print "\n" print "right leaf count: {}".format(len(best_r)) print best_r print r print "\n"
def run(): cwd = os.getcwd() print("Selecionando pdf mais recente ...") time.sleep(1.5) files = glob.glob(cwd + "/*.pdf") files.sort(key=os.path.getmtime, reverse=True) arq = files[0] print(f"{arq[len(cwd):]} selecionado!") time.sleep(.5) while True: try: page = int(input("Página do Seu Gabarito: ")) break except: print("Digite um número!!\n") while True: try: id = input("Matrícula: ") int(id) break except: print("Digite apenas números") while True: quest = input("Gabarito (sem espaços):") quest = quest.split() if len(quest) == 1: quest = quest[0] break else: print("Digite suas Respostas sem espaços!!") name = input("Nome e Sobrenome: ") output = "Gabarito_" + "_".join(name.split()) split(arq, page, output + ".pdf") transform(id, quest, output, name, parameters)
def mixed(files_train=None, files_validation=None, path='', suffix='simple', batch_size=32, pixels=144, num_classes=2, augment=False): gen_train = GeneratorCNN(filenames=files_train, mode='feather', categories=num_classes, batch_size=batch_size, pixels=pixels) print('Training Generator loaded') df = func.toDF_all(files_validation, reb=False) X_validation, y_validation = func.split(df, categories=num_classes, augment_data=augment) X_validation = X_validation / 255 print('X validation shape', X_validation.shape) print('y validation shape', y_validation.shape) print('Validation Generator loaded') return gen_train, X_validation, y_validation
input( "How many chances do you want? Please reply with an integer equal to or greater than 1. " )) except ValueError: print(invalidNumber) continue if chances < 1: print(invalidNumber) continue while chances != 0: # Defines the variables for the hangman selectedWord = random.choice( words) # Picks a random word from the words list splitWord = split( selectedWord) # Splits that word into single characters blankWord = "_" * len( selectedWord ) # Prints as many "_" as there are characters for the selected word splitBlankWord = split( blankWord) # Splits the blank word into single characters while chances != 0 and splitBlankWord != splitWord: guess = input(f"Guess a letter: {splitBlankWord}") if guess in splitWord: for i in range(len(splitWord)): if splitWord[i] != guess: continue splitBlankWord[i] = guess
net = BdLSTMAE(input_size=30, hidden_size=200, num_layers=1) net = net.cuda() net.load_state_dict(torch.load(network_weights_path)) mean_pose = find_translated_mean_pose( num_markers=10, path='/home/henryp/PycharmProjects/MoGap/ground_truth_data', central_marker_num=4) max_val = find_max_val( path='/home/henryp/PycharmProjects/MoGap/ground_truth_data') original_data, split_data = split(data=file_path, index_cols=True, size=200, padding=1, result_dim=(0, 200, 30)) original_data[original_data == 0.0000] = np.nan original_data = torch.Tensor(original_data) original_data = normalize_series(original_data, mean_pose=mean_pose, data_max_val=max_val) estimates = np.empty((0, 200, 30)) criterion = nn.MSELoss() for window in split_data: window = torch.Tensor(window).unsqueeze(0) window = window.float() window = normalize_series(window, mean_pose=mean_pose,
opts.update({'siz': 142, 'num_fold': 10, 'jj': jj, 'tt': 11, 'zz': 11}) c_t2 = np.moveaxis(c_t1, 0, -1) p_t2 = np.moveaxis(p_t1, 0, -1) Coronal_controls = np.fliplr(np.flipud(c_t2[opts['zz']:opts['zz']+opts['siz'], opts['jj'], opts['tt']:opts['tt']+opts['siz'], :])) Coronal_patients = np.fliplr(np.flipud(p_t2[opts['zz']:opts['zz']+opts['siz'], opts['jj'], opts['tt']:opts['tt']+opts['siz'], :])) Coronal_controls = np.moveaxis(Coronal_controls, -1, 0) Coronal_patients = np.moveaxis(Coronal_patients, -1, 0) X = np.concatenate((Coronal_controls, Coronal_patients), axis=0) y = np.concatenate((np.ones(Coronal_controls.shape[0], dtype = int), np.zeros(Coronal_patients.shape[0], dtype = int)), axis=0) T, S = split(X, y, opts['num_fold']) opts.update({'T': T, 'S': S, 'ypred': [], 'ypredr':[], 'acc': []}) for j in range(0, len(S['ytrain'])): net = cnn_network(opts) net.fit(x=S['xtrain'][j], y=S['ytrain'][j], epochs=opts['mx_epochs'], shuffle=True, validation_freq=opts['val_freq'], validation_data=(S['xval'][j], S['yval'][j]), batch_size=opts['batch_size']) ypred = np.argmax(net.predict(T['xtest']), axis=-1) acc = 0 for i in range(0, len(ypred)): if (ypred[i] == T['ytest'][i][0]): acc = acc + 1 opts['acc'].append(acc/len(ypred)) opts['ypred'].append(ypred) now = datetime.now() # current date and time dt2 = now.strftime("%m-%d-%y-%H-%M-%S-%f")
def run(n, test, group_path, plotFlag, saveFlag): clear_all() # Loading setups configurations config = setup() #rm-list_resources() to find address for smu address_2612b = 26 #running tests (smua measures iv and smub measures r) [smu_2612b, rm] = gpib(address_2612b) [readingsV_sipm, readingsI_sipm] = IVComplete(smu_2612b, config) readingsV_sipm_neg, readingsV_sipm_pos, readingsI_sipm_neg, readingsI_sipm_pos = split( readingsV_sipm, readingsI_sipm) if plotFlag == 1: graphIV_neg = plot(readingsV_sipm_neg, readingsI_sipm_neg, 'Vsipm', 'Isipm', 1, log=False, errorbars_2612=True) graphIV_pos = plot(readingsV_sipm_pos, readingsI_sipm_pos, 'Vsipm', 'Isipm', 2, log=False, errorbars_2612=True) else: graphIV_neg = 'NULL' graphIV_pos = 'NULL' if saveFlag == 1: group_path_pos = group_path + " (rq)" group_path_neg = group_path + " (vbr)" save_iv(readingsV_sipm_neg, readingsI_sipm_neg, graphIV_neg, n, group_path_pos) save_iv(readingsV_sipm_pos, readingsI_sipm_pos, graphIV_pos, n, group_path_neg) time.sleep(0) readingsI_sipm_dark = DarkCurrent(smu_2612b, config) number = [] for g in range(len(readingsI_sipm_dark)): number.append(g) if plotFlag == 1: graphIV = plot(number, readingsI_sipm_dark, 'N', 'Isipm', 3, log=False, errorbars_2612=True) else: graphIV = 'NULL' if saveFlag == 1: group_path_dark = group_path + " (idark)" save_dark(readingsI_sipm_dark, graphIV, n, group_path_dark) [readingsI_sipm_led, readingsI_led, readingsV_led] = LEDTest(smu_2612b, config) if plotFlag == 1: graphIV_led = plot(readingsI_led, readingsI_sipm_led, 'Iled', 'Isipm', 4, log=True, errorbars_2612=True, xflag='I') else: graphIV_led = 'NULL' if saveFlag == 1: group_path_dark = group_path + " (LED)" save_led(readingsI_sipm_led, readingsI_led, readingsV_led, graphIV_led, n, group_path_dark) rm.close return
def run(n, test, group_path, plotFlag, saveFlag): # Loading setups configurations config = setup() #rm-list_resources() to find address for smu address_2612b = 26 address_2400 = 24 clear_all() #running tests (smua measures iv and smub measures r) [smu_2612b, smu_2400, rm] = gpib(address_2612b, address_2400) if test == 'iv': [readingsV_sipm, readingsI_sipm, readingsR] = IVComplete(smu_2612b, smu_2400, config) smu_2612b.write('reset()') smu_2612b.write('smua.nvbuffer1.clear()') smu_2612b.write('smub.nvbuffer1.clear()') smu_2400.write('*CLS') readingsV_sipm_neg, readingsV_sipm_pos, readingsI_sipm_neg, readingsI_sipm_pos, readingsR_neg, readingsR_pos = split( readingsV_sipm, readingsI_sipm, readingsR) number_neg = [] number_pos = [] for g in range(len(readingsR_neg)): number_neg.append(g) for g in range(len(readingsR_pos)): number_pos.append(g) if plotFlag == 1: graphR_neg = plot(number_neg, readingsR_neg, 'N', 'R', 1, log=False, errorbars_2400=True) graphR_pos = plot(number_pos, readingsR_pos, 'N', 'R', 2, log=False, errorbars_2400=True) graphIV_neg = plot(readingsV_sipm_neg, readingsI_sipm_neg, 'Vsipm', 'Isipm', 3, log=False, errorbars_2612=True) graphIV_pos = plot(readingsV_sipm_pos, readingsI_sipm_pos, 'Vsipm', 'Isipm', 4, log=False, errorbars_2612=True) else: graphR_neg = 'NULL' graphR_pos = 'NULL' graphIV_neg = 'NULL' graphIV_pos = 'NULL' if saveFlag == 1: group_path_pos = group_path + " (rq)" group_path_neg = group_path + " (vbr)" save_iv(readingsV_sipm_neg, readingsI_sipm_neg, readingsR_neg, graphIV_neg, graphR_neg, n, group_path_pos) save_iv(readingsV_sipm_pos, readingsI_sipm_pos, readingsR_pos, graphIV_pos, graphR_pos, n, group_path_neg) time.sleep(45) [readingsI_sipm, readingsR] = DarkCurrent(smu_2612b, smu_2400, config) smu_2612b.write('reset()') smu_2612b.write('smua.nvbuffer1.clear()') smu_2612b.write('smub.nvbuffer1.clear()') smu_2400.write('*CLS') number = [] for g in range(len(readingsR)): number.append(g) if plotFlag == 1: graphR = plot(number, readingsI_sipm, 'N', 'Isipm', 5, log=False, errorbars_2612=True) else: graphR = 'NULL' if saveFlag == 1: group_path_dark = group_path + " (idark)" save_dark(readingsI_sipm, readingsR, graphR, n, group_path_dark) rm.close return elif test == 'self_heating': [ readingsV_sipm, readingsI_sipm, readingsV_led, readingsI_led, readingsR ] = SelfHeating(smu_2612b, smu_2400, config) smu_2612b.write('reset()') smu_2612b.write('smua.nvbuffer1.clear()') smu_2612b.write('smub.nvbuffer1.clear()') smu_2400.write('*CLS') rm.close Number = [] for i in range(0, len(readingsR)): Number.append(i) if plotFlag == 1: graphR = plot(Number, readingsR, 'N', 'R', 1) graphIV = plot(readingsI_led, readingsI_sipm, 'Iled', 'Isipm', 2, log=True, errorbars_2612=True) else: graphR = 'NULL' graphIV = 'NULL' if saveFlag == 1: save(readingsV_sipm, readingsI_sipm, readingsV_led, readingsI_led, readingsR, graphIV, graphR, n, group_path) return else: print(str(test) + " is not a valid mode") return
def split(): print(f.split('abc,defg', 2)) print(f.split('abc,defg', ',')) print(f.split(['abc','def','ghij'], 2))
def split(self, *args, **kwargs): return F.split(self, *args, **kwargs)