def run_gene_model(): train_cm_X = train_cm.iloc[:, 0:-ADDITIONAL_COLUMN].values train_cm_Y = train_cm.loc[:, LABEL_COLUMN].values train_cm_Y_one_hot = to_categorical(label_encoder.transform(train_cm_Y), num_classes=len(class_list)) test_cm_X = test_cm.iloc[:, 0:-ADDITIONAL_COLUMN].values test_cm_Y = test_cm.loc[:, LABEL_COLUMN].values test_cm_Y_one_hot = to_categorical(label_encoder.transform(test_cm_Y), num_classes=len(class_list)) parallel_model_gene = st_nn(train_cm_X.shape[1], train_cm_Y_one_hot.shape[1]) parallel_model_gene.fit(train_cm_X, train_cm_Y_one_hot, batch_size=batch_size, epochs=epochs) y_pred = parallel_model_gene.predict(test_cm_X, verbose=1) # get true label (categorical) y_true = test_cm_Y # convert categorical string label to numerical label y_true = label_encoder.transform(y_true) # plot ROC and confusion matrix out_path = os.path.join(DATASET_PATH, "results_gene_model") mkdirs(out_path) model_eval(y_pred, y_true, class_list=class_list, prefix=os.path.join(out_path, "single_model_gene_count"))
def prediction(): filename = request.args.get('filename') pred, probs = model_eval( os.path.join(app.config['UPLOAD_FOLDER'], filename)) probs = sorted(list(probs.items()), key=lambda x: x[1], reverse=True) return render_template('display.html', filename=filename, prediction=pred, probabilities=probs)
def get_eval_op(): dataset = DataGenerator( sample_range=config.eval_samples, shuffle_samples=True, max_patches_per_sample=config.max_patches_per_sample ).make_dataset( split_lhs_rhs=False ) X, Y = dataset.make_one_shot_iterator().get_next() ops = model_eval(X, Y, params={'n_candidates': tf.constant(config.n_candidates)}) return ops
def run_combine_model(): # create input batch for training model. eg. ([image, cm], label) * batch_size train_gen = DataGenerator(df=df, cm_df=train_cm, le=label_encoder, cm_len=cm_shape, batch_size=batch_size) # create test data generator. eg. [image, cm] * 1 test_gen = DataGenerator(df=df, cm_df=test_cm, le=label_encoder, shuffle=False, is_train=False, batch_size=1, cm_len=cm_shape) # compile model parallel_model_combine, model_ = st_comb_nn((SIZE[0], SIZE[1], N_CHANNEL), (cm_shape, ), len(class_list)) # training model parallel_model_combine.fit_generator(generator=train_gen, steps_per_epoch=len(train_gen), epochs=epochs) # predict on test dataset to get predict values with shape (n_classes,) y_pred = parallel_model_combine.predict_generator(generator=test_gen, verbose=1) # get true label (categorical) y_true = test_cm.loc[:, LABEL_COLUMN].values # convert categorical string label to numerical label y_true = label_encoder.transform(y_true) # plot ROC and confusion matrix out_path = os.path.join(DATASET_PATH, "results_combine_model") mkdirs(out_path) model_eval(y_pred, y_true, class_list=class_list, prefix=os.path.join(out_path, "combine_model"))
def eval(): global net data = request.get_json() image = Image.open(io.BytesIO(base64.b64decode(data["data"]))).convert("RGB") return {"data": model_eval(net, image)}