def train(): data = request.get_json() user_id = data['user_id'] languages = ['en', 'fr', 'ar'] folder_name = str(time.time()) for lang in languages: train_model(lang, folder_name) # SAVE MODEL RECORD database.session.add(Model(path=folder_name, user_id=user_id)) database.session.commit() return 'trainingCompleted', 200
def fine_tune(): if request.method == 'GET': return render_template("finetune.html") image = request.form["img"] label = request.form["label"] x = imread(parse_image(image.encode('ascii'), label), mode='L') x = np.invert(x) x = resize(x, (28, 28)) x = x.flatten() * 255 global clf prediction = clf.predict([x]) if int(prediction) == int(label): return "Я думаю это {} и это правильно! Думаю, учиться мне тут нечему.".format( label) clf = train_model() return "Эта цифра так похожа на {}, но это {}. Попробую больше так не ошибаться!".format( prediction, label)
from flask import Flask, render_template, request from scipy.misc import imsave, imread, imresize import numpy as np import re import base64 import random import pickle from skimage.transform import resize from model.model import MV101_KNN from model.train import train_model import os data_path = './data/' clf = train_model() app = Flask(__name__) @app.route('/') @app.route('/prediction/', methods=['GET', 'POST']) def predict(): if request.method == 'GET': return render_template("prediction.html") image = request.form["img"] parse_image(image.encode('ascii')) x = imread(data_path + 'predictimage.png', mode='L') x = np.invert(x) x = resize(x, (28, 28))
from model.parser import args from model.train import train_model from model.generate import generate_from if(args.generate): text = generate_from(args.from_model, args.start_text, args.n_text, args.layers, args.eta) print(text) elif(args.train): train_model(args) else: print('No valid configuration, use --help.')
result_dict = dict( sorted(result_dict.items(), key=lambda item: item[1], reverse=True)) for record in result_dict: print(f'{record}: {result_dict[record]}') else: criterion = nn.CrossEntropyLoss() optimizer_ft = optim.SGD(model_ft.parameters(), lr=0.001, momentum=0.9) # Decay LR by a factor of 0.1 every 7 epochs exp_lr_scheduler = lr_scheduler.StepLR(optimizer_ft, step_size=7, gamma=0.1) model_conv = train_model(model_ft, dataloaders, dataset_sizes, criterion, optimizer_ft, exp_lr_scheduler, device, num_epochs=25) torch.save(model_conv.state_dict(), 'state_dict_model.pt') visualize_model(model_conv, dataloaders, list(pets_datasets['val'].classes), device, 6)
def train(): train_model() logging.info("train done.")
from model.eval import calc_auc from model.optimise import optimise from model.train import train_model from utils.read_data import load_data if __name__ == '__main__': train, test = load_data() # define how many round we want to try max_evals = 10 best = optimise(train, max_evals) # show the best parameter print(best) # train our model bst = train_model(train, **best) # testing y = test.get_label() y_pred = bst.predict(test) # show auc auc = calc_auc(y, y_pred) print(auc)
scatter_filename = f'scatter-{y_axis}-{x_axis}.png' scatter_full_filename = os.path.join(app.config['UPLOAD_FOLDER'], scatter_filename) plt.savefig(scatter_full_filename) return scatter_full_filename # Make an instance of Flask app = Flask(__name__) # Configure SECRET_KEY, which is needed to keep the client-side sessions secure in Flask. app.config['SECRET_KEY'] = 'someRandomKey' app.config['UPLOAD_FOLDER'] = IRIS_ALBUM # check whether the model is already trained or not if not os.path.isfile('trained_models/iris-model.pkl'): train_model() # Load the model and scaler trained_model = joblib.load('trained_models/iris-model.pkl') trained_scaler = joblib.load('trained_models/iris-scaler.pkl') # Creat an WTForm Class, TextField Represents <input type = 'text'> class FlowerForm(FlaskForm): sep_len = TextField('Sepal Length (cm): ') sep_wid = TextField('Sepal Width (cm): ') pet_len = TextField('Petal Length (cm): ') pet_wid = TextField('Petal Width (cm): ') submit = SubmitField('Analyze') # Endpoint: homepage