forked from dvbuntu/autonomous
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_model.py
More file actions
52 lines (39 loc) · 1.4 KB
/
Copy pathbasic_model.py
File metadata and controls
52 lines (39 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import math
import numpy as np
import h5py
from tqdm import tqdm
import keras
from keras.models import Sequential, Model
from keras.layers.core import Dense, Dropout, Activation, Flatten, Reshape
from keras.layers import Embedding, Input, merge
from keras.layers.recurrent import SimpleRNN, LSTM
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.optimizers import SGD, Adam, RMSprop
import sklearn.metrics as metrics
# frame size
nrows = 16
ncols = 16
# accel, speed, distance, angle
real_in = Input(shape=(4,), name='real_input')
# video frame in, grayscale
frame_in = Input(shape=(1,nrows,ncols))
# convolution for image input
conv = Convolution2D(1,3,3,border_mode='same',
activation='relu')
conv_l = conv(frame_in)
pool_l = MaxPooling2D(pool_size=(2,2))(conv_l)
flat = Flatten()(pool_l)
M = merge([flat,real_in], mode='concat', concat_axis=1)
A = Dense(1, activation='linear')(M)
P = Dense(1, activation='linear')(M)
model = Model(input=[real_in, frame_in], output=[A,P])
model.compile(loss='mean_squared_error',
optimizer='rmsprop',
metrics=['accuracy'])
nsamples = 1000
fake_real = np.random.random((nsamples,4))
fake_frame = np.random.random((nsamples,1,nrows,ncols))
fake_A = np.random.random(nsamples)
fake_P = np.random.random(nsamples)
h = model.fit([fake_real, fake_frame], [fake_A, fake_P], batch_size = 32, nb_epoch=10, verbose=1)