Created
April 30, 2019 07:00
-
-
Save AdroitAnandAI/4d66594da26e8d8283a513ba2011232d to your computer and use it in GitHub Desktop.
Lenet implementation for Acceleration in Keras
This file contains 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
# The model is inspired from the LeNet, 1998 paper by Le Cunn | |
# Credits: https://github.com/keras-team/keras/blob/master/examples/mnist_cnn.py | |
from __future__ import print_function | |
import keras | |
from keras.datasets import mnist | |
from keras.models import Sequential | |
from keras.layers import Dense, Dropout, Flatten | |
from keras.layers import Conv2D, MaxPooling2D | |
from keras import backend as K | |
from keras.layers.normalization import BatchNormalization | |
batch_size = 128 | |
epochs = 30 | |
model = Sequential() | |
model.add(Conv2D(256, kernel_size=(3, 3), | |
activation='relu', | |
input_shape=input_shape)) #Convolution | |
model.add(MaxPooling2D(pool_size=(2, 2))) #Subsampling | |
model.add(Dropout(0.25)) | |
model.add(Conv2D(128, (3, 3), activation='relu')) #Convolution | |
model.add(MaxPooling2D(pool_size=(2, 2))) #Subsampling | |
model.add(Dropout(0.25)) | |
model.add(Flatten()) | |
model.add(Dense(128, activation='relu')) # Full Connection | |
model.add(Dropout(0.5)) | |
model.add(Dense(64, activation='relu')) # Full Connection | |
model.add(Dropout(0.5)) | |
model.add(Dense(1)) | |
model.compile(loss='mse',#loss=keras.losses.categorical_crossentropy, | |
optimizer=keras.optimizers.Adadelta(), | |
metrics=['mean_squared_error', 'mean_absolute_error', 'mean_absolute_percentage_error', 'cosine_proximity']) | |
# train_xs, train_accels, val_xs, val_accels | |
history=model.fit(train_xs, train_accels, | |
batch_size=batch_size, | |
epochs=epochs, | |
verbose=1, | |
validation_data=(val_xs, val_accels)) | |
score = model.evaluate(val_xs, val_accels, verbose=0) | |
# To try predict acceleration using train data | |
pred = model.predict(train_xs) | |
#Print acceleration first n frames | |
for i in pred[0:500]: | |
print(i*180/scipy.pi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment