-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Important COMMIT: improve load data speed, 100 times faster
- Loading branch information
1 parent
bffa162
commit ad6d0a3
Showing
6 changed files
with
148 additions
and
62 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from keras.models import Sequential | ||
from keras.layers.core import Dense, Dropout, Flatten, RepeatVector | ||
from keras.layers import LSTM | ||
from keras.layers import Convolution2D, MaxPooling2D | ||
from keras.layers.normalization import BatchNormalization | ||
from keras.layers.wrappers import TimeDistributed | ||
from util import categorical_accuracy_per_sequence | ||
|
||
def build_cv_cnn_lstm(channels, width, height, lstm_output_size, nb_classes): | ||
model = Sequential() | ||
# 1 conv | ||
model.add(Convolution2D(32, 3, 3, border_mode='same', activation='relu', | ||
input_shape=(channels, height, width))) | ||
model.add(BatchNormalization(mode=0, axis=1)) | ||
# 2 conv | ||
model.add(Convolution2D(32, 3, 3, border_mode='same', activation='relu')) | ||
model.add(BatchNormalization(mode=0, axis=1)) | ||
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2))) | ||
# 3 conv | ||
model.add(Convolution2D(64, 3, 3, border_mode='same', activation='relu')) | ||
model.add(BatchNormalization(mode=0, axis=1)) | ||
# 4 conv | ||
model.add(Convolution2D(64, 3, 3, border_mode='same', activation='relu')) | ||
model.add(BatchNormalization(mode=0, axis=1)) | ||
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2))) | ||
# 5 conv | ||
model.add(Convolution2D(128, 3, 3, border_mode='same', activation='relu')) | ||
model.add(BatchNormalization(mode=0, axis=1)) | ||
# 6 conv | ||
model.add(Convolution2D(128, 3, 3, border_mode='same', activation='relu')) | ||
model.add(BatchNormalization(mode=0, axis=1)) | ||
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2))) | ||
# 7 conv | ||
model.add(Convolution2D(256, 3, 3, border_mode='same', activation='relu')) | ||
model.add(BatchNormalization(mode=0, axis=1)) | ||
# 8 conv | ||
model.add(Convolution2D(256, 3, 3, border_mode='same', activation='relu')) | ||
model.add(BatchNormalization(mode=0, axis=1)) | ||
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2,2))) | ||
# flaten | ||
a = model.add(Flatten()) | ||
# 1 dense | ||
model.add(Dense(256, activation='relu')) | ||
model.add(BatchNormalization()) | ||
model.add(Dropout(0.5)) | ||
# 2 dense | ||
model.add(Dense(512, activation='relu')) | ||
model.add(BatchNormalization()) | ||
model.add(Dropout(0.5)) | ||
# lstm | ||
model.add(RepeatVector(lstm_output_size)) | ||
model.add(LSTM(512, return_sequences=True)) | ||
model.add(TimeDistributed(Dropout(0.5))) | ||
model.add(TimeDistributed(Dense(nb_classes, activation='softmax'))) | ||
# model.summary() | ||
model.compile(loss='categorical_crossentropy', | ||
optimizer='adam', | ||
metrics=[categorical_accuracy_per_sequence], | ||
sample_weight_mode='temporal' | ||
) | ||
|
||
return model |
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
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
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
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