Beispiel #1
0
imagery_path = r'E:\Research\LandCoverMapping\Experiment\qianshan\Final_2\Classification\ImageData\out\com_nor_fit_tri.tif'

# Set the path where to output the final classified image
class_file_path = r'E:\Research\LandCoverMapping\Experiment\qianshan\Final_2\Classification\ImageData\out\class_svm_fit_tri.tif'

# set the split points according to csv files for training
split_points = [2, 32]

# Get all data ready for training and predicting 
# data_tuple contains: x_s, y_s, rows, cols, data_frame, geo_trans_list, 
#                      proj_str, num_bands
data_tuple = utils.prepare_data(imagery_path, train_file_path, split_points)

print("get tif data!")
# Train the classifier
clf_svm = svm.SVC()

t1 = time.time()
clf_svm.fit(data_tuple[0], data_tuple[1])
t2 = time.time()
print("svm_fit_tri fitting time: " + str(t2 - t1))

# Predict lables based on image data
t3 = time.time()
z_ps=clf_svm.predict(data_tuple[2][0])
t4 = time.time()
print("svm_fit_tri predicting time: " + str(t4 - t3))

# Output the classification result
utils.output_lables_to_tif(z_ps, class_file_path, data_tuple[2][1], data_tuple[2][2], 
                           data_tuple[2][3], data_tuple[2][4], 1)
Beispiel #2
0
        z_ps.append(tmp_z_ps)
        tmp_w_ps = base_clf.score(x_s, y_s.astype(int) - 1)
        w_ps.append(tmp_w_ps)

    # collect memory
    del (data_tuple)
    gc.collect()

    print(file_index)

# integrate results of base classifiers
final_list = []
lables = [np.arange(1, n_lables + 1), np.zeros([n_lables])]
cnt = 0
for pos_index in range(0, len(z_ps[0])):
    lables[1] = np.zeros([n_lables])
    for vote_index in range(0, len(z_ps)):
        # The results of the original classification is the subscript values,
        # plus 1, convert them to Lables
        lable_n = z_ps[vote_index][pos_index] + 1
        for lables_index in lables[0]:
            if lables_index == lable_n:
                lables[1][lables_index - 1] += w_ps[vote_index]
                continue

    final_list.append(lables[0][np.argmax(lables[1])])

# Output the classification result
utils.output_lables_to_tif(final_list, class_file_path, rows, cols,
                           geo_trans_list, proj_str, 1)