def reports(data, label): _, _te_pred = classifier.predict(data) _te_pred = np.argmax(_te_pred, axis=1) if opt.DATASET == 'Indian': targets = ['Alfalfa', 'Corn-notill', 'Corn-mintill', 'Corn' , 'Grass-pasture', 'Grass-trees', 'Grass-pasture-mowed', 'Hay-windrowed', 'Oats', 'Soybean-notill', 'Soybean-mintill', 'Soybean-clean', 'Wheat', 'Woods', 'Buildings-Grass-Trees-Drives', 'Stone-Steel-Towers'] elif opt.DATASET == 'Salinas': targets = ['Brocoli_green_weeds_1', 'Brocoli_green_weeds_2', 'Fallow', 'Fallow_rough_plow', 'Fallow_smooth', 'Stubble', 'Celery', 'Grapes_untrained', 'Soil_vinyard_develop', 'Corn_senesced_green_weeds', 'Lettuce_romaine_4wk', 'Lettuce_romaine_5wk', 'Lettuce_romaine_6wk', 'Lettuce_romaine_7wk', 'Vinyard_untrained', 'Vinyard_vertical_trellis'] elif opt.DATASET == 'PaviaU': targets = ['Asphalt', 'Meadows', 'Gravel', 'Trees', 'Painted metal sheets', 'Bare Soil', 'Bitumen', 'Self-Blocking Bricks', 'Shadows'] elif opt.DATASET == 'KSC': targets = ['Scrub', 'Willow Swamp', 'Cabbage Palm Hammock', 'Cabbage Palm/Oak', 'Slash Pine', 'Oak/Broadleaf Hammock', 'Hardwood Swamp', 'Graminoid Marsh', 'Spartina Marsh', 'Cattail Marsh', 'Salt Marsh', 'Mud Flats', 'Water'] elif opt.DATASET == 'Pavia': targets = ['Water', 'Trees', 'Asphalt', 'Self-Blocking-Bricks', 'Bitumen', 'Tiles', 'Shadows', 'Meadows', 'Bare soil'] else: raise NotImplementedError classification = classification_report(label, _te_pred, target_names=targets) oa = accuracy_score(label, _te_pred) confusion = confusion_matrix(label, _te_pred) each_acc, aa = aa_and_each_acc(confusion) kappa = cohen_kappa_score(label, _te_pred) return classification, confusion, oa * 100, each_acc * 100, aa * 100, kappa * 100
def result(): if request.method == 'POST': to_predict_list = request.form.to_dict() to_predict_list = list(to_predict_list.values()) to_predict_list = list(map(float, to_predict_list)) to_predict = np.array(to_predict_list).reshape(1, 10) if (flag == 0): result = loaded_model.predict(to_predict) else: from new_model import classifier as new_loaded_model result = new_loaded_model.predict(to_predict) final_result = result[0] if int(final_result) == 1: prediction = 'Customer will exit' else: prediction = 'Customer will not exit' return render_template("result.html", prediction=prediction, values=re_values, labels=re_labels, firstChartOne=firstChartOne, firstChartTwo=firstChartTwo, secChartOne=secChartOne, secChartTwo=secChartTwo, exitedAgeValues=exitedAgeValues, exitedAgeLabels=exitedAgeLabels)
def predict(self, input_data): # classes classes = {True : "Customer will churn! :heavy_multiplication_x:", False: "Customer will not churn! :heavy_check_mark:"} # image name image_names = {True: "churn", False: "not_churn"} # encode data input_data[0][1] = self.encoder1.transform([input_data[0][1]])[0] input_data[0][2] = self.encoder2.transform([input_data[0][2]])[0] # scale data transformed_data = self.scaler.transform(input_data) # predict pred = classifier.predict(transformed_data) > 0.5 return classes[pred[0][0]], image_names[pred[0][0]]
def test_func(te_data, te_label): print("Start testing using test data!") _, te_pred = classifier.predict(te_data) te_label = tf.argmax(te_label, axis=1) te_pred = tf.argmax(te_pred, axis=1) classification = classification_report(te_label, te_pred) print(classification) classification, confusion, oa, each_acc, aa, kappa = reports( te_data, te_label) classification = str(classification) confusion = str(confusion) report = os.path.join( opt.RESULT, str(opt.DATASET) + "_" + str(opt.ACQUISITION) + "_loop" + str(loop) + "_report.txt") with open(report, 'w') as f: f.write('\n') f.write("DATASET:{}".format(str(opt.DATASET))) f.write('\n') f.write( "WINDOW_SIZE:{}, use_SuperPCA:{}, CHANNEL:{}, BATCH_SIZE:{}, BUDGET:{}" .format(str(opt.WINDOW_SIZE), str(opt.use_SuperPCA), str(opt.CHANNEL), str(opt.BATCH_SIZE), str(opt.BUDGET))) f.write('\n') f.write('\n') f.write('\n') f.write('Each: {}'.format(each_acc)) f.write('\n') f.write('{} Kappa accuracy (%)'.format(kappa)) f.write('\n') f.write('{} Overall accuracy (%)'.format(oa)) f.write('\n') f.write('{} Average accuracy (%)'.format(aa)) f.write('\n') f.write('\n') f.write('{}'.format(classification)) f.write('\n') f.write('{}'.format(confusion))
else: pass margin = int((opt.WINDOW_SIZE - 1) / 2) raw_data_padded = pad_zeros(raw_data, margin=margin) '''calculate the predicted image''' pred_map = np.zeros((raw_label.shape[0], raw_label.shape[1])) for row in range(raw_label.shape[0]): for col in range(raw_label.shape[1]): target = int(raw_label[row, col]) if target == 0: continue else: img_patch = patch(raw_data_padded, row, col) data_te_img = img_patch.reshape(1, img_patch.shape[0], img_patch.shape[1], img_patch.shape[2], 1).astype('float32') _, prediction = classifier.predict(data_te_img) prediction = np.argmax(prediction, axis=1) pred_map[row][col] = prediction + 1 spectral.save_rgb(os.path.join( opt.RESULT, str(opt.DATASET) + "_" + str(opt.ACQUISITION) + "_predictions.jpg"), pred_map.astype(int), colors=spectral.spy_colors) spectral.save_rgb(os.path.join(opt.RESULT, str(opt.DATASET) + "_groundtruth.jpg"), raw_label, colors=spectral.spy_colors)