def computate_train_and_eval(classes, batch, epochs_without_learning, model_name, kfold, pretrain): # Cria a arquitetura densene1t pre-treinada print('Inicializando a rede...') print('Estrutura da {}: '.format(model_name)) model_ft, model_input_size = new_model(classes, model_name, pretrain) print(model_ft) print("Pré-Treinada = %s" % pretrain) #Inicializa objeto para criacao dos graficos if (kfold < 2): grafico = statistics_plot(model_name, 'train_eval') else: grafico = statistics_plot(model_name, 'kfold') model_ft = train(model_ft, model_name, model_input_size, grafico, classes, batch, epochs_without_learning, kfold, pretrain) #Testa a rede sobre o dataset de test eval(grafico, model_input_size, model_name, model_ft, inside_trainning=True) save_dir = "./modelo_treinado/" + model_name + "-best" + ".pth" save_dir_grafico = "./estatisticas/" + model_name + ".html" #Salva o modelo treinado em disco print('Salvando modelo em ', save_dir) torch.save(model_ft.state_dict(), save_dir) print('Modelo salvo com sucesso') #Exibe o grafico no navegador grafico.show() grafico.write_html(save_dir_grafico)
def computate_eval_only(classes, batch, epochs_without_learning, model_name, kfold, pretrained): save_dir_grafico = "./modelo_treinado/" + model_name + "eval-only" + ".html" model_ft, model_input_size = new_model(classes, model_name, pretrained) grafico = statistics_plot(model_name, 'eval') eval(grafico, model_input_size, model_name, model_ft, inside_trainning=False) grafico.show() grafico.write_html(save_dir_grafico)
def train_bj_model(y_train, y_test, x1_train, x1_test, x2_train, x2_test, x3_train, x3_test): model = new_model() model.fit( { 'tem_input': x1_train, 'spa_input': x2_train, 'meo_input': x3_train }, [y_train], epochs=80, validation_split=0.2, batch_size=128, shuffle=True, verbose=1) score = model.evaluate(x={ 'tem_input': x1_test, 'spa_input': x2_test, 'meo_input': x3_test }, y=y_test, batch_size=30, verbose=1, sample_weight=None, steps=None) print(score) pre = (model.predict({ 'tem_input': x1_test, 'spa_input': x2_test, 'meo_input': x3_test })) a = smape(y_test, pre) print(smape(y_test, pre)) s = '0509//' '1st' + '.h5' model.save(s) np.save('result', a) return a, score
def compile_model(): return model.new_model(INPUT_SIZE, OUTPUT_SIZE)
def model_vacio(): return md.new_model()
y_train, y_test = g48[:6300], g48[6300:] x1_train, x1_test = tem[:6300], tem[6300:] x2_train, x2_test = spc[:6300], spc[6300:] x3_train, x3_test = me[:6300], me[6300:] #x1_train, x1_test ,\ #x2_train,x2_test, \ #x3_train , x3_test,\ #y_train, y_test =train_test_split(tem,spc,me,g48,test_size=0.33, random_state=42) from model import new_model model = new_model() model.fit({ 'tem_input': x1_train, 'spa_input': x2_train, 'meo_input': x3_train }, [y_train], epochs=100, validation_split=0.2, batch_size=128, shuffle=True, verbose=1) score = model.evaluate(x={ 'tem_input': x1_test, 'spa_input': x2_test,