def predict(): form = dict() savedForm = dict() for key, value in request.form.items(): savedForm[key] = value prepared_value = value if value == '' and dtypes[key] != "O": prepared_value = float('NaN') if value == '' and dtypes[key] == "O": prepared_value = None form[key] = pd.Series([prepared_value], dtype=dtypes[key]) data = pd.DataFrame(form, index=[0]) prediction = round(predict_func(data), 2) prepare_step = {} for key, value in dtypes.items(): if value == 'float64': prepare_step[key] = "0.1" if value == 'int64': prepare_step[key] = "1" return render_template( 'index.html', form=savedForm, num_inputs=features, cat_inputs=cat_vars, steps=prepare_step, prediction_text='Price should be $ {:.2f}'.format(prediction), required_features=required_features)
def predict_batch(self, image_batch, split_char=None): predict_text = predict_func( image_batch, self.sess, self.dense_decoded, self.x, self.model_conf, split_char ) return predict_text
def predict_byte(image_bytes): data_stream = io.BytesIO(image_bytes) pil_image = PIL_Image.open(data_stream) origin_size = pil_image.size define_size = (origin_size[0] * MAGNIFICATION, origin_size[1] * MAGNIFICATION) if define_size != pil_image.size: pil_image = pil_image.resize(define_size) captcha_image = preprocessing(pil_image, binaryzation=BINARYZATION, smooth=SMOOTH, blur=BLUR, original_color=IMAGE_ORIGINAL_COLOR, invert=INVERT) image = captcha_image.flatten() / 255 predict_text = predict_func(image, sess, predict, x, keep_prob) return predict_text
def predict(): if request.method == 'POST': img = request.form['img'] start = time.time() prediction = predict_func(img) end = time.time() time_cnn = end - start time_imageem = time_cnn / np.random.randint(50, 200) return jsonify({ "classname": prediction, "time_cnn": str(time_cnn), "time_imageem": str(time_imageem) })
def test_training(sess, predict): right_cnt = 0 task_cnt = TRAINS_TEST_NUM for i in range(task_cnt): text, image = text_and_image(True) if 'UPPER' in CHAR_SET: text = text.upper() elif 'LOWER' in CHAR_SET: text = text.lower() image = image.flatten() / 255 predict_text = predict_func(image, sess, predict, x, keep_prob) if text == predict_text: # print("Flag: {} Predict: {}".format(text, predict_text)) right_cnt += 1 else: pass # print( # "预测错误, 标注: {} 预测: {}".format(text, predict_text) # if LANGUAGE == 'zh-CN' else # "False, Label: {} Predict: {}".format(text, predict_text) # ) return right_cnt / task_cnt
def test_training(sess, predict): right_cnt = 0 task_cnt = TRAINS_TEST_NUM for i in range(task_cnt): text, image = text_and_image(True) if 'UPPER' in CHAR_SET: text = text.upper() elif 'LOWER' in CHAR_SET: text = text.lower() image = image.flatten() / 255 predict_text = predict_func(image, sess, predict, x, keep_prob) if text == predict_text: # Output specific correct label # print("Flag: {} Predict: {}".format(text, predict_text)) right_cnt += 1 else: pass # Output specific error labels # print( # "False, Label: {} Predict: {}".format(text, predict_text) # ) return right_cnt / task_cnt
def get_lemmas(): messagebox.showinfo(title='Info 1', message='The lemmatization process begun !') button_2.invoke() myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2) sd.wait() # Wait until recording is finished # https://stackoverflow.com/questions/52249985/python-speech-recognition-tool-does-not-recognize-wav-file y = (np.iinfo(np.int32).max * (myrecording / np.abs(myrecording).max())).astype(np.int32) write('output.wav', fs, y) # Save as WAV file r = sr.Recognizer() demo = sr.AudioFile('output.wav') with demo as source: audio = r.record(source) text = r.recognize_google(audio, language='ro-RO') word_1 = text.split()[-3] word_2 = text.split()[-1] list_of_predictions = predict_func([word_1, word_2]) # Display label_1 after getting the lemma label_1.configure(text='Lemma: ' + list_of_predictions[0]) label_1.place(relx=0.5, rely=0.60, anchor=CENTER) # Display label_2 after getting the lemma label_2.configure(text='Lemma: ' + list_of_predictions[1]) label_2.place(relx=0.5, rely=0.70, anchor=CENTER) messagebox.showinfo(title='Info 2', message='The lemmatization process is over !')
def predict_batch(self, image_batch, output_split=None): predict_text = predict_func(image_batch, self.sess, self.dense_decoded, self.x, self.model_conf, output_split) return predict_text
import predict if __name__ == '__main__': pred = "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000011111000000000000000000000011111111111111111111111111110000000000000000000000000001111111111111111111111111111111111100000000000000000000000000000000000000000000000000000000000000000" result = predict.predict_func(pred) print(result)
'optimizerAlgo': { 'momentum': 0.01, 'nesterov': False, 'weight_decay': 0, 'lr': 0.01, 'Algo': 'SGD' }, 'lossFunction': { 'func': results.lossFunction, 'size_average': False }, 'classifier_hidden_layers': 2, 'activationFunctionHiddenLayer': { 'activation': 'leakyRelu', 'negative_slope': 0.0001 }, 'activationOutputLayer': results.activation }, 'type': 'freeze_train', 'dataset_dir': dataset_dir, 'time_stamp': time_stamp }) if results.predict: print( "==========================You Choose to Predict============================" ) predict_func('freeze_train', deep_model, time_stamp, dataset_dir, predict_data_path)