Esempio n. 1
0
def train_RS():
    george_points_tif = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/shp/Training_points_clip_dropTransition_add.tif"
    # training_tif = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/all_19bands_stack.tif"
    # outmodel = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/george_data_19bands_add.pkl"
    # training_summary = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/george_data_19bands_add.csv"
    # band_labels = ["ndvi", "ci", "psri", "gndvi", "s2_rep", "ireci", "s2_b", "s2_g",
    #                "s2_r", "s2_nir", "hv", "vv","s2_20m_1","s2_20m_2","s2_20m_3","s2_20m_4","s2_20m_5","s2_20m_6","seg"]
    #bands = 19

    training_tif = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/all_13bands_stack_v2.tif"
    outmodel = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/george_data_13bands_add_255_eRF_v2.pkl"
    training_summary = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/george_data_13bands_add_255_v2.csv"
    band_labels = [
        "ndvi", "ci", "psri", "gndvi", "s2_rep", "ireci", "s2_b", "s2_g",
        "s2_r", "s2_nir", "hv", "vv", "seg"
    ]
    bands = 13

    features, labels = PYEO_model.get_training_data_tif(
        image_path=training_tif, training_tif_path=george_points_tif)

    features_df = pd.DataFrame(data=features,
                               columns=band_labels).astype(np.int32)

    scale = preprocessing.MinMaxScaler(feature_range=(0, 255)).fit(features)
    features_trans = scale.transform(features)
    features_trans_df = pd.DataFrame(features_trans,
                                     index=features_df.index,
                                     columns=features_df.columns)

    features_df.describe()
    features_trans_df.describe()

    labels_df = pd.DataFrame(data=labels,
                             columns=['class_name']).astype(np.int)

    features_df["class_name"] = labels_df["class_name"]

    features_df.describe().to_csv(training_summary)

    #PYEO_model.train_rs_simple(X_train_input=features_trans,y_train_input=labels,outModel_path=outmodel, bands = bands)
    PYEO_model.train_eRF_gs_simple(X_train_input=features_trans,
                                   y_train_input=labels,
                                   outModel_path=outmodel,
                                   bands=bands)
    image_tobe_classified = training_tif

    PYEO_model.classify_image(model_path=outmodel,
                              in_image_path=image_tobe_classified,
                              out_image_path=image_tobe_classified[:-4] +
                              "_classified_13bands_255_eRF2_v2.tif",
                              rescale_predict_image=scale)
    image_tobe_classified = "/media/ubuntu/Data/Ghana/north_region/s2_NWN/images/stacked/with_s1_seg/composite_20180122T102321_T30NWN.tif"

    PYEO_model.classify_image(model_path=outmodel,
                              in_image_path=image_tobe_classified,
                              out_image_path=image_tobe_classified[:-4] +
                              "_classified_13bands_255_eRF2_v2.tif",
                              rescale_predict_image=scale)
Esempio n. 2
0
def test_histmatching_classify():
    training_tif = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/all_13bands_stack_v2.tif"
    george_points_tif = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/shp/Training_points_clip_dropTransition_add.tif"
    input_model = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/george_data_13bands_add_255_eRF_v2.pkl"
    image_tobe_classified = "/media/ubuntu/Data/Ghana/north_region/s2/images/stacked/with_s1_seg/composite_20180122T102321_T30NWN.tif"

    features, labels = PYEO_model.get_training_data_tif(
        image_path=training_tif, training_tif_path=george_points_tif)

    scale = preprocessing.MinMaxScaler(feature_range=(0, 255)).fit(features)

    PYEO_model.classify_image(model_path=input_model,
                              in_image_path=image_tobe_classified,
                              out_image_path=image_tobe_classified[:-4] +
                              "_classified_13bands_255_eRF2_v4.tif",
                              rescale_predict_image=scale,
                              ref_img_for_linear_shift=training_tif,
                              generate_mask=False)
Esempio n. 3
0
def do_classify(working_dir):
    training_tif = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/all_13bands_stack_v2.tif"
    george_points_tif = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/shp/Training_points_clip_dropTransition_add.tif"
    input_model = "/media/ubuntu/Data/Ghana/cocoa_upscale_test/george_data_13bands_add_255_eRF_v2.pkl"

    features, labels = PYEO_model.get_training_data_tif(
        image_path=training_tif, training_tif_path=george_points_tif)
    scale = preprocessing.MinMaxScaler(feature_range=(0, 255)).fit(features)

    os.chdir(working_dir)

    for image in os.listdir("images/stacked/with_s1_seg"):
        if image.endswith(".tif"):
            image_tobe_classified = os.path.join("images/stacked/with_s1_seg",
                                                 image)
            out_image_path = os.path.join("output/",
                                          image[:-4] + "_13bands_255_eRF.tif")

            PYEO_model.classify_image(model_path=input_model,
                                      in_image_path=image_tobe_classified,
                                      out_image_path=out_image_path,
                                      rescale_predict_image=scale,
                                      ref_img_for_linear_shift=training_tif,
                                      generate_mask=False)