예제 #1
0
def randomtree_lidaralldata17():
    alltest_y = np.array([])
    alltest_y.shape = 0
    K.clear_session()
    model = lidar_model()
    model.load_weights('model/lidar_model17.h5')
    print(model.summary())
    model = Model(inputs=model.input,
                  outputs=model.get_layer('dense_2').output)
    print(model.summary())
    rf = joblib.load('model/rflidar17.model')
    for m in range(8, 2412):
        print str(m)
        lidar_batch_patch = np.zeros(
            (8344, patch_size_LID, patch_size_LID, lidar_channel),
            dtype=np.uint8)
        for n in range(8, 8352):
            bias = int(patch_size_LID / 2)
            upper_y = m - bias
            left_x = n - bias
            lidar_batch_patch[n -
                              8] = lidar_change[upper_y:upper_y +
                                                patch_size_LID,
                                                left_x:left_x + patch_size_LID]
        pre_labels = model.predict(lidar_batch_patch)
        pre_labels = pre_labels.reshape((8344, 512))
        predicted_yone = rf.predict(pre_labels)
        alltest_y = np.concatenate((alltest_y, predicted_yone), 0)
    alltest_y = alltest_y.reshape((2404, 8344))
    np.save("Result/alltest_y17.npy", alltest_y)
    K.clear_session()
예제 #2
0
def randomtree_lidar3():
    test_x = np.array([])
    test_x.shape = 0, 512
    test_y = np.array([])
    test_y.shape = 0,
    K.clear_session()
    model = lidar_model()
    model.load_weights('model/lidar_model3.h5')
    print(model.summary())
    model = Model(inputs=model.input,
                  outputs=model.get_layer('dense_2').output)
    print(model.summary())
    for j in range(int(label_location3[0].shape[0] // 1000)):
        print str(j)
        lidar_batch_label = np.zeros((batch_size), dtype=int)
        lidar_batch_patch = np.zeros(
            (batch_size, patch_size_LID, patch_size_LID, lidar_channel),
            dtype=np.uint8)
        for i in range(1000):
            num = j * 1000 + i
            X = label_location3[0][num]
            Y = label_location3[1][num]
            lab = train_sets3[X, Y]
            lidar_batch_label[i] = lab
            y = label_location3[0][num]
            x = label_location3[1][num]
            bias = int(patch_size_LID / 2)
            upper_y = y - bias
            left_x = x - bias
            upper_y, left_x = boundary_judge(upper_y, left_x, patch_size_LID,
                                             lidar.shape[0], lidar.shape[1])
            lidar_batch_patch[i] = lidar[upper_y:upper_y + patch_size_LID,
                                         left_x:left_x + patch_size_LID]
        test_y = np.concatenate((test_y, lidar_batch_label), 0)
        pre_labels = model.predict(lidar_batch_patch)
        pre_labels = pre_labels.reshape((test_size, 512))
        test_x = np.concatenate((test_x, pre_labels), 0)
    K.clear_session()
    rf = RandomForestClassifier(criterion="entropy",
                                max_features="sqrt",
                                n_estimators=400,
                                min_samples_leaf=2,
                                n_jobs=-1,
                                oob_score=True)
    rf.fit(test_x, test_y)
    joblib.dump(rf, 'model/rflidar3.model')
    print('OK!')
예제 #3
0
def lidartrain17():
    total_number = 25000
    save_number = 1000
    K.clear_session()
    model = lidar_model()
    t0 = time.time()
    for i in range(total_number):
        print "i " + str(i)
        lidar, label = lidar_train_data17(batch_size=batch_size_LID, patch_size=patch_size_LID)
        model.fit(lidar, label, epochs=5, batch_size=batch_size_LID)
        if i % save_number == 0:
            print "save model......"
            model.save_weights('model/lidar_model17.h5')
    K.clear_session()
    t1 = time.time()
    print "spend total time:" + str(round(t1 - t0, 2)) + "s"
    K.clear_session()
예제 #4
0
def lidar_test():
    K.clear_session()
    model = lidar_model()
    model.load_weights('model/lidartwo_model.h5')
    label = np.array([])
    label.shape = 0, 2
    for m in range(8, 2412):
        print str(m)
        lidar_batch_patch = np.zeros(
            (8344, patch_size_LID, patch_size_LID, lidar_channel),
            dtype=np.uint8)
        for n in range(8, 8352):
            bias = int(patch_size_LID / 2)
            upper_y = m - bias
            left_x = n - bias
            lidar_batch_patch[n - 8, ...] = lidar_change[upper_y:upper_y +
                                                         patch_size_LID,
                                                         left_x:left_x +
                                                         patch_size_LID, :]
        pre_labels = model.predict(lidar_batch_patch)
        label = np.concatenate((label, pre_labels), 0)
    label = label.reshape(2404, 8344, 2)
    np.save('Result/labelvggtwo.npy', label)
    K.clear_session()