def Predict(): record = 1 if askyesno('Record Mode', 'Yes to Record else No to Import Wavfile'): message = predict.pred(0) else: Path = askopenfilename() message = predict.pred(1, Path=Path) showinfo('Result', message)
def test_one_as_train(ckpt_path): predict_param = { 'model_name': 'Seq2seq_12', 'ckpt_path': ckpt_path, 'cangtou': '', 'keywords': '', 'test_set': '', 'eval_set': 'resource/dataset/test_10k_1k.txt', 'use_planning': False, 'bleu_eval': False, 'poem_type': 'poem7', 'train_mode': 'kw2poem', 'note': '', 'as_train': True, # 'pred_soft': pred_soft, # 'template': template, 'hard_rhyme': True, 'hard_tone': False, # 'w1': w1, # 'w2': w2, } save_file = pred(predict_param) lv_rate, yun_rate = get_rate(save_file, 'result') lm = get_lm(save_file) return save_file, lv_rate, yun_rate, lm
def translate(self): word = self.LineEdit1.toPlainText() if not word: return results = pred(source_str = word,infer_model=infer_model,infer_sess=infer_sess) print(results) self.LineEdit2.setText(results)
def upload_file(): if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: #flash('No file part') return redirect(request.url) file = request.files['file'] # if user does not select file, browser also # submit a empty part without filename if file.filename == '': return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) result = predict.pred( os.path.join(app.config['UPLOAD_FOLDER'], filename)) return jsonify(result) #return json.dumps({'status':'success'}) return
def uploads(): if request.method == "POST": #file = request.files['file'] uploaded_files = request.files.getlist("file[]") weight_path2 = os.path.join("static", "Classify_model.h5") filenames = { "bird": [], "book": [], "butterfly": [], "cattle": [], "chicken": [], "elephant": [], "horse": [], "phone": [], "sheep": [], "shoes": [], "spider": [], "squirrel": [], "watch": [] } for file in uploaded_files: if file and is_allowed_file(file.filename): basepath = os.path.dirname(__file__) filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) img_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) class_index, class_name = pred(img_path, weight_path2) filenames[class_name].append(filename) # print(class_index,class_name) result = show_json(filename, class_name) #data.append(result) #res_json = json.dumps({"status": "200", "msg": "success","data":data}) return render_template( 'upload_more_ok.html', filenames=filenames, ) return render_template("upload_more.html", path="./images/test.jpg")
def cinc(): # print("scheduler") global tcount,tyawn,tear,tearate,ta,tb tdata[tcount]=[tyawn,tear,average(ta),average(tb)] #print(pred(tdata[tcount])) x=pred(tdata[tcount]) if(x[0]=="Drowsy"): alarm.playalarm() #print(len(ta),len(tb)) # with open('data2.csv', 'a', newline='') as file: # writer = csv.writer(file) # # writer.writerow(["Yawn", "Eye Blink", "Left Eye","Right Eye"]) # writer.writerow(tdata[tcount]) tyawn=0 tear=0 ta=[] tb=[] tearate=0 tcount+=1 # print(tdata) return
def __call__(self, img): ori_im = img.copy() dt_boxes, elapse = self.text_detector(img) print("dt_boxes num : {}, elapse : {}".format(len(dt_boxes), elapse)) if dt_boxes is None: return None, None img_crop_list = [] dt_boxes = sorted_boxes(dt_boxes) for bno in range(len(dt_boxes)): tmp_box = copy.deepcopy(dt_boxes[bno]) img_crop = self.get_rotate_crop_image(ori_im, tmp_box) img_crop_list.append(img_crop) # rec_res, elapse = self.text_recognizer(img_crop_list) rec_res = [] elapse = 0 for img in img_crop_list: txt, score, time_u = pred(img) rec_res.append([txt, score]) elapse += time_u print("rec_res num : {}, elapse : {}".format(len(rec_res), elapse)) # self.print_draw_crop_rec_res(img_crop_list, rec_res) return dt_boxes, rec_res
def predictStuff(qns, file): return pred(file, qns)
def get(self): s = parser.parse_args()['query'] ans = pred(s) print(ans, s) return 'Prediction: ' + str(ans)
def results(): s = request.args['data'] ans = pred(s) return render_template("result.html", data=ans)
def find(self, instance): img, result = pred(self.path.text) predictor.outmenu.setData(img1 = self.path.text, result1 = f"{result}") predictor.screenmanager.current = "OutMenu"
from emg import ( Preprocess, BuildCNN , plot_history, train,Preprocess_all ) from predict import ( pred ) import numpy as np def bond(x_train,x_train1,y_train,y_train1): x_train = np.concatenate([x_train,x_train1], axis=0) y_train = np.concatenate([y_train,y_train1], axis=0) for l in [x_train, y_train]: np.random.seed(1) np.random.shuffle(l) return x_train,y_train if __name__ == '__main__': #x_train, x_val, y_train, y_val =Preprocess_all() x_train, x_val, y_train, y_val =Preprocess(0,0) x_train1, x_val1, y_train1, y_val1=Preprocess(1,0.5) x_train , y_train = bond(x_train,x_train1,y_train,y_train1) model = BuildCNN() hist = train(model,x_train, x_val1, y_train, y_val1) #hist = train(model,x_train, x_val, y_train, y_val) plot_history(hist) pred(x_val1,y_val1)
def sentiment(): vars = request.args.items() googpred=pred(getGoogleData('ya29.eQCnabTuxqmxPBwAAAB2AZe6wAdMBSKEvMO7GjvKRuSQsfpiJz2KrnWFA_KnCg','my-user-agent/1.0')) print googpred fbpred=pred(getFBMSG('a10cf4775b52e5412537f495696b3a15')) print fbpred
def chance_fraud(): return predict.pred()
def predict_result(self): return pred( ([self.age, self.sex, self.cigs, self.chol, self.bp, self.glucose ]), 'true_seasup.pkl')
print(X_train.shape, y_train.shape) print(X_val.shape, y_val.shape) classnum = [[548, 540, 392, 542, 256, 532, 375, 514, 231], [5472, 13750, 1331, 2573, 1122, 4572, 981, 3363, 776]] # Train! model = net.netconv() logger = keras.callbacks.CSVLogger("logs/train.log") cp = keras.callbacks.ModelCheckpoint("./cp/weights.{epoch:02d}.hdf5") X_full = np.concatenate((X_train, X_val)) y_full = np.concatenate((y_train, y_val)) print(X_full.shape, y_full.shape) model.fit(X_full, y_full, batch_size=32, epochs=25, validation_split=.5, callbacks=[logger, cp]) print("Predicting") p = predict.pred(X, model) i_p = predict.toImg(p, y.shape) i_gt = predict.toImg(y, y.shape, palette=i_p.getpalette()[1:]) print(list(i_p.getdata())[100:130]) print(list(i_gt.getdata())[100:130]) print(i_p.getpalette()) print(i_gt.getpalette()) i_p.save("pred.png") i_gt.save("ground.png") predict.compare(i_p, i_gt).save("comp.png")