Beispiel #1
0
    def main():
        from lightgbm import LGBMModel
        from sklearn.metrics import mean_absolute_error

        from assess import assess

        df = load_data('train', '../input', sample_size=10000)
        columns = split_columns_by_types(df)
        df.drop(df[df['win_place_perc'].isnull()].index, inplace=True)
        model_params = dict(
            objective='regression',
            metric='mae',
            # n_estimators=20000,
            n_estimators=2000,
            num_leaves=31,
            learning_rate=0.05,
            bagging_fraction=0.7,
            bagging_seed=0,
            num_threads=4,
            colsample_bytree=0.7)

        assessment_log = assess(
            LGBMModel(**model_params),
            df,
            columns,
            metrics=mean_absolute_error,
            n_splits=1,
            early_stopping_rounds=200,
            # early_stopping_rounds=20000,
            verbose=1,
        )
        del df

        best_model = [step for step in assessment_log if step['best']].pop()
        df_test = load_data('test', '../input')
        pipeline = best_model['pipeline']
        model = best_model['model']
        x_test = pipeline.transform(df_test)
        pred_test = model.predict(x_test)
        del df_test, x_test

        df_sub = load_data('sub', '../input', normilize_names=False)
        df_sub['winPlacePerc'] = pred_test
        df_sub_adjusted = postprocessing(pred_test, '../input')
        df_sub.to_csv('submission.csv', index=False)
        df_sub_adjusted.to_csv('submission_adjusted.csv', index=False)
        print(
            np.corrcoef(df_sub['winPlacePerc'],
                        df_sub_adjusted['winPlacePerc']))
 def __procces_and_filter_predict__(self, net_prediction):
     """
     :return: detected bounding boxes [x1,y1,x2,y2] + [score, class prob, class id]
     """
     roi_objs = postprocessing(net_prediction,
                               num_classes=self.num_classes,
                               obj_conf_thr=self.object_confindce_threshold,
                               nms_thr=self.non_maximum_sus_thr)[0]
     if len(roi_objs) > 0:
         roi_obj_ind = [(self.classes[int(obj[-1])]
                         in self.classes_to_track) for obj in roi_objs]
         roi_obj_ind = np.array(roi_obj_ind) * (roi_objs[:, -2].numpy() >=
                                                self.class_confidence)
         roi_objs = roi_objs[np.arange(len(roi_objs))[roi_obj_ind]]
     return roi_objs
Beispiel #3
0
aug_dir = '../result/aug/'

k = 10

y_min = np.array([0, 0, 0.08])
y_max = np.array([180, 75, 0.78])

for i in range(k):
    model_fcnn.append(load_model(fcnn_dir + 'model' + str(i) +'.h5'))
    model_pca.append(load_model(pca_dir + 'model' + str(i) +'.h5'))
    model_aug.append(load_model(aug_dir + 'model' + str(i) +'.h5'))

    x, y = load_data(fcnn_dir + 'data' + str(i) + '.h5')
    data_fcnn['x'], data_fcnn['y'] = x, y
    y_pred = model_fcnn[i].predict(x)
    y_pred, y = utils.postprocessing(y_pred, y, y_min, y_max)
    accuracy_fcnn.append(utils.metric(utils.create_df(y, y_pred)))

    x, y = load_data(pca_dir + 'data' + str(i) + '.h5')
    data_pca['x'], data_pca['y'] = x, y
    y_pred = model_pca[i].predict(x)
    y_pred, y = utils.postprocessing(y_pred, y, y_min, y_max)
    accuracy_pca.append(utils.metric(utils.create_df(y, y_pred)))

    x, y = load_data(aug_dir + 'data' + str(i) + '.h5')
    data_aug['x'], data_aug['y'] = x, y
    y_pred = model_aug[i].predict(x)
    y_pred, y = utils.postprocessing(y_pred, y, y_min, y_max)
    accuracy_aug.append(utils.metric(utils.create_df(y, y_pred)))

print('fcnn')

# %% ############## Check multi head precictions ##############################
u_net = U_Net(dir_dict=DIR_DICT)
sess = u_net.load_session_from_file(nn_name)
n = 47

pred = u_net.get_prediction_from_path(
    sess, [x_test[n]],
    method=METHOD,
    tgt_size=(IMG_HEIGHT, IMG_WIDTH),
    compatibility_multiplier=32,
    full_prediction=True)
pred = utils.trsf_proba_to_binary(np.array(pred))
markers = label(pred[0, :, :, 1] * (1 - pred[0, :, :, 2]))[0]
pred_water = utils.postprocessing(pred, method='watershed')
fig, axs = plt.subplots(1, 5, sharex=False)
axs[0].imshow(utils.read_image(x_test[n]))
axs[0].set_title('image')
axs[1].imshow(pred[0, :, :, 0], cmap='jet')
axs[1].set_title('pred full mask')
axs[2].imshow(pred[0, :, :, 2], cmap='jet')
axs[2].set_title('pred borders')
axs[3].imshow(markers, cmap='jet')
axs[3].set_title('pred markers')
axs[4].imshow(pred_water[0], cmap='jet')
axs[4].set_title('pred watershed')

sess.close()

# %%###########################################################################