def show_lanes(sw, img_warped, img_orig, filename): img = img_warped.copy() if sw.left: fitx_points_warped = np.float32([np.transpose(np.vstack([sw.left.fitx, sw.ploty]))]) fitx_points = cv2.perspectiveTransform(fitx_points_warped, perspective_correction_inv) left_line_warped = np.int_(fitx_points_warped[0]) left_line = np.int_(fitx_points[0]) n = len(left_line) for i in range(n - 1): cv2.line(img_orig, (left_line[i][0], left_line[i][1]), (left_line[i + 1][0], left_line[i + 1][1]), (0, 255, 0), 5) cv2.line(img, (left_line_warped[i][0], left_line_warped[i][1]), (left_line_warped[i + 1][0], left_line_warped[i + 1][1]), (0, 255, 0), 5) if sw.right: fitx_points_warped = np.float32([np.transpose(np.vstack([sw.right.fitx, sw.ploty]))]) fitx_points = cv2.perspectiveTransform(fitx_points_warped, perspective_correction_inv) right_line_warped = np.int_(fitx_points_warped[0]) right_line = np.int_(fitx_points[0]) for i in range(len(right_line) - 1): cv2.line(img_orig, (right_line[i][0], right_line[i][1]), (right_line[i + 1][0], right_line[i + 1][1]), (0, 0, 255), 5) cv2.line(img, (right_line_warped[i][0], right_line_warped[i][1]), (right_line_warped[i + 1][0], right_line_warped[i + 1][1]), (0, 0, 255), 5) save_dir(img, "lanes_warped_", filename) return save_dir(img_orig, "lanes_orig_", filename)
def warp(img, filename): img_persp = img.copy() cv2.line(img_persp, perspective_dest[0], perspective_dest[1], (255, 255, 255), 3) cv2.line(img_persp, perspective_dest[1], perspective_dest[2], (255, 255, 255), 3) cv2.line(img_persp, perspective_dest[2], perspective_dest[3], (255, 255, 255), 3) cv2.line(img_persp, perspective_dest[3], perspective_dest[0], (255, 255, 255), 3) cv2.line(img_persp, perspective_trapezoid[0], perspective_trapezoid[1], (0, 192, 0), 3) cv2.line(img_persp, perspective_trapezoid[1], perspective_trapezoid[2], (0, 192, 0), 3) cv2.line(img_persp, perspective_trapezoid[2], perspective_trapezoid[3], (0, 192, 0), 3) cv2.line(img_persp, perspective_trapezoid[3], perspective_trapezoid[0], (0, 192, 0), 3) save_dir(img_persp, "persp_", filename) return save_dir( cv2.warpPerspective(img, perspective_correction, warp_size, flags=cv2.INTER_LANCZOS4), "warp_", filename)
def threshold(channel_threshold, channel_edge, filename): # Gradient threshold binary = np.zeros_like(channel_edge) height = binary.shape[0] threshold_up = 15 threshold_down = 60 threshold_delta = threshold_down - threshold_up for y in range(height): binary_line = binary[y, :] edge_line = channel_edge[y, :] threshold_line = threshold_up + threshold_delta * y / height binary_line[edge_line >= threshold_line] = 255 save_dir(binary, "threshold_edge_only_", filename) save_dir(channel_threshold, "channel_only_", filename) binary[(channel_threshold >= 140) & (channel_threshold <= 255)] = 255 binary_threshold = np.zeros_like(channel_threshold) binary_threshold[(channel_threshold >= 140) & (channel_threshold <= 255)] = 255 return (save_dir(binary, "threshold_", filename), save_dir(binary_threshold, "threshold_other", filename))
def edge_detection(channel, filename): edge_x = cv2.Scharr(channel, cv2.CV_64F, 1, 0) # Edge detection using the Scharr operator edge_x = np.absolute(edge_x) return save_dir(np.uint8(255 * edge_x / np.max(edge_x)), "edge_", filename)
CLASS = 1 VALI = 0.1 DROP = 0.5 PATIENCE = 50 BATCH = 128 TEST_DATA = sys.argv[1] SAVE_DIR = sys.argv[2] MODEL = './model_bi_lstm.h5' # load word2vec model wv_model = w2v.load('./word_vec') # wv_weight = wv_model.wv.syn0 ## load vocab vocab = dict([(k, v.index) for k, v in wv_model.wv.vocab.items()]) x_setence = utils.load_data(TEST_DATA, file_type = 'test') x_setence = utils.split_setence(x_setence) x_setence_id = utils.w2id(x_setence, vocab) x_test = pad_sequences(x_setence_id) model = load_model(MODEL) predicted = model.predict(x_test) predicted = np.around(predicted) print(predicted) utils.save_dir(predicted, SAVE_DIR)
import numpy as np import sys from keras.models import load_model import utils import models MEAN = 3.58171208604 TEST_DATA = sys.argv[1] ANS_PATH = sys.argv[2] MODEL = './model.h5' x_test = utils.load_data(TEST_DATA, file_type='test') model = load_model(MODEL, custom_objects={'rmse': models.rmse}) y_pred = model.predict(np.hsplit(x_test, 2)) print('--y_pred:\n', y_pred) # y_pred = utils.post_process(y_pred, bias = MEAN) y_pred = utils.post_process(y_pred, round=False, bias=MEAN) print('--ans:\n', y_pred) utils.save_dir(data=y_pred, path=ANS_PATH)