This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from keras.preprocessing.sequence import pad_sequences | |
| from keras.utils import to_categorical | |
| import numpy as np | |
| def pad(sequences, max_len): | |
| return pad_sequences(sequences, maxlen=max_len) | |
| def categorize_labels(labels) : | |
| return to_categorical(np.asarray(labels)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from keras.preprocessing.text import Tokenizer | |
| from keras.preprocessing.sequence import pad_sequences | |
| def tokenize(top_n_words, texts): | |
| tokenizer = Tokenizer(num_words=top_n_words) | |
| tokenizer.fit_on_texts(texts) | |
| sequences = tokenizer.texts_to_sequences(texts) | |
| word_index = tokenizer.word_index |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def dot_product(x, kernel): | |
| """ | |
| Wrapper for dot product operation, in order to be compatible with both | |
| Theano and Tensorflow | |
| Args: | |
| x (): input | |
| kernel (): weights | |
| Returns: | |
| """ | |
| if K.backend() == 'tensorflow': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Write a function 'filter()' that implements a multi- | |
| // dimensional Kalman Filter for the example given | |
| //============================================================================ | |
| #include <iostream> | |
| #include "Dense" | |
| #include <vector> | |
| using namespace std; | |
| using namespace Eigen; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Write a program that will iteratively update and | |
| # predict based on the location measurements | |
| # and inferred motions shown below. | |
| def update(mean1, var1, mean2, var2): | |
| new_mean = float(var2 * mean1 + var1 * mean2) / (var1 + var2) | |
| new_var = 1./(1./var1 + 1./var2) | |
| return [new_mean, new_var] | |
| def predict(mean1, var1, mean2, var2): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_batches(arr, n_seqs, n_steps): | |
| '''Create a generator that returns batches of size | |
| n_seqs x n_steps from arr. | |
| Arguments | |
| --------- | |
| arr: Array you want to make batches from | |
| n_seqs: Batch size, the number of sequences per batch | |
| n_steps: Number of sequence steps per batch | |
| ''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def sigmoid(x): | |
| """ | |
| Calculate sigmoid | |
| """ | |
| return 1/(1+np.exp(-x)) | |
| def sigmoid_prime(x): | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use histogram on both side of the lane to obtain starting | |
| # point for lane line scanning. | |
| midpoint = np.int(histogram.shape[0]/2) | |
| leftx_base = np.argmax(histogram[:midpoint]) | |
| rightx_base = np.argmax(histogram[midpoint:]) + midpoint | |
| out_img = np.dstack((binary_warped, binary_warped, binary_warped))*255 | |
| # Choose the number of sliding windows | |
| nwindows = 9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import cv2 | |
| import matplotlib.pyplot as plt | |
| import matplotlib.image as mpimg | |
| image = mpimg.imread('cutout1.jpg') | |
| # Define a function to compute color histogram features | |
| def color_hist(img, nbins=32, bins_range=(0, 256)): | |
| # Compute the histogram of the RGB channels separately |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import np as numpy | |
| import cv2 | |
| """ | |
| draw rectangle boxes at given coordinates on the given image. | |
| """ | |
| def draw_boxes(img, bboxes, color=(0, 0, 255), thick=6): | |
| # make a copy of the image | |
| draw_img = np.copy(img) | |
| # draw each bounding box on your image copy using cv2.rectangle() |