x = Dropout(0.15)(x) tStream = Model(inputs=sStream.input, outputs=x) # Create full 2 stream network spatial_average = Lambda(function=lambda x: K.mean(x, axis=1), output_shape=lambda shape: (shape[0], ) + shape[2:])(sStream.outputs[-1]) spatial_out = Dense(classes, activation='sigmoid')(spatial_average) temporal_out = Dense(classes, activation='sigmoid')(tStream.outputs[-1]) averaged = Average()([spatial_out, temporal_out]) model = Model(inputs=sStream.input, outputs=averaged) model.summary() return model if __name__ == "__main__": from training import TrainingSuite training_suite = TrainingSuite(BATCH_SIZE, EPOCHS, TRAIN_DIR, TEST_DIR, FRAME_LENGTH, FRAME_WIDTH, FRAME_NUM, preprocess_input) model = TS_CNN_LSTM(INPUT_SHAPE, KERNEL_SHAPE, POOL_SHAPE, CLASSES) training_suite.evaluation(model, WEIGHT_FILE_NAME, gen_logs=False)
model.add(TimeDistributed(Conv2D(filters=64, kernel_size=kernel_shape))) model.add(TimeDistributed(Activation("relu"))) model.add(TimeDistributed(BatchNormalization())) model.add(TimeDistributed(MaxPooling2D(pool_size=pool_shape))) model.add(TimeDistributed(Conv2D(filters=64, kernel_size=kernel_shape))) model.add(TimeDistributed(Activation("relu"))) model.add(TimeDistributed(BatchNormalization())) model.add(TimeDistributed(MaxPooling2D(pool_size=pool_shape))) model.add(TimeDistributed(Flatten())) model.add(LSTM(512, return_sequences=True)) # Temporal Mean Pooling model.add( Lambda(function=lambda x: K.mean(x, axis=1), output_shape=lambda shape: (shape[0], ) + shape[2:])) model.add(Dense(classes, name='output', activation='sigmoid')) model.summary() return model if __name__ == "__main__": from training import TrainingSuite training_suite = TrainingSuite(BATCH_SIZE, EPOCHS, TRAIN_DIR, TEST_DIR, FRAME_LENGTH, FRAME_WIDTH, FRAME_NUM) model = cnn_lstm(INPUT_SHAPE, KERNEL_SHAPE, POOL_SHAPE, CLASSES) training_suite.evaluation(model, WEIGHT_FILE_NAME)