def test_multi_dqn_input():
input1 = Input(shape=(2, 3))
input2 = Input(shape=(2, 4))
x = Concatenate()([input1, input2])
x = Flatten()(x)
x = Dense(2)(x)
model = Model(inputs=[input1, input2], outputs=x)
memory = SequentialMemory(limit=10, window_length=2)
processor = MultiInputProcessor(nb_inputs=2)
for double_dqn in (True, False):
agent = DQNAgent(model, memory=memory, nb_actions=2, nb_steps_warmup=5, batch_size=4,
processor=processor, enable_double_dqn=double_dqn)
agent.compile('sgd')
agent.fit(MultiInputTestEnv([(3,), (4,)]), nb_steps=10)
python类concatenate()的实例源码
def test_multi_continuous_dqn_input():
nb_actions = 2
V_input1 = Input(shape=(2, 3))
V_input2 = Input(shape=(2, 4))
x = Concatenate()([V_input1, V_input2])
x = Flatten()(x)
x = Dense(1)(x)
V_model = Model(inputs=[V_input1, V_input2], outputs=x)
mu_input1 = Input(shape=(2, 3))
mu_input2 = Input(shape=(2, 4))
x = Concatenate()([mu_input1, mu_input2])
x = Flatten()(x)
x = Dense(nb_actions)(x)
mu_model = Model(inputs=[mu_input1, mu_input2], outputs=x)
L_input1 = Input(shape=(2, 3))
L_input2 = Input(shape=(2, 4))
L_input_action = Input(shape=(nb_actions,))
x = Concatenate()([L_input1, L_input2])
x = Concatenate()([Flatten()(x), L_input_action])
x = Dense(((nb_actions * nb_actions + nb_actions) // 2))(x)
L_model = Model(inputs=[L_input_action, L_input1, L_input2], outputs=x)
memory = SequentialMemory(limit=10, window_length=2)
processor = MultiInputProcessor(nb_inputs=2)
agent = NAFAgent(nb_actions=nb_actions, V_model=V_model, L_model=L_model, mu_model=mu_model,
memory=memory, nb_steps_warmup=5, batch_size=4, processor=processor)
agent.compile('sgd')
agent.fit(MultiInputTestEnv([(3,), (4,)]), nb_steps=10)
def test_multi_cem_input():
input1 = Input(shape=(2, 3))
input2 = Input(shape=(2, 4))
x = Concatenate()([input1, input2])
x = Flatten()(x)
x = Dense(2)(x)
model = Model(inputs=[input1, input2], outputs=x)
memory = EpisodeParameterMemory(limit=10, window_length=2)
processor = MultiInputProcessor(nb_inputs=2)
agent = CEMAgent(model, memory=memory, nb_actions=2, nb_steps_warmup=5, batch_size=4,
processor=processor, train_interval=50)
agent.compile()
agent.fit(MultiInputTestEnv([(3,), (4,)]), nb_steps=100)
def test_cdqn():
# TODO: replace this with a simpler environment where we can actually test if it finds a solution
env = gym.make('Pendulum-v0')
np.random.seed(123)
env.seed(123)
random.seed(123)
nb_actions = env.action_space.shape[0]
V_model = Sequential()
V_model.add(Flatten(input_shape=(1,) + env.observation_space.shape))
V_model.add(Dense(16))
V_model.add(Activation('relu'))
V_model.add(Dense(1))
mu_model = Sequential()
mu_model.add(Flatten(input_shape=(1,) + env.observation_space.shape))
mu_model.add(Dense(16))
mu_model.add(Activation('relu'))
mu_model.add(Dense(nb_actions))
action_input = Input(shape=(nb_actions,), name='action_input')
observation_input = Input(shape=(1,) + env.observation_space.shape, name='observation_input')
x = Concatenate()([action_input, Flatten()(observation_input)])
x = Dense(16)(x)
x = Activation('relu')(x)
x = Dense(((nb_actions * nb_actions + nb_actions) // 2))(x)
L_model = Model(inputs=[action_input, observation_input], outputs=x)
memory = SequentialMemory(limit=1000, window_length=1)
random_process = OrnsteinUhlenbeckProcess(theta=.15, mu=0., sigma=.3, size=nb_actions)
agent = NAFAgent(nb_actions=nb_actions, V_model=V_model, L_model=L_model, mu_model=mu_model,
memory=memory, nb_steps_warmup=50, random_process=random_process,
gamma=.99, target_model_update=1e-3)
agent.compile(Adam(lr=1e-3))
agent.fit(env, nb_steps=400, visualize=False, verbose=0, nb_max_episode_steps=100)
h = agent.test(env, nb_episodes=2, visualize=False, nb_max_episode_steps=100)
# TODO: evaluate history
def test_ddpg():
# TODO: replace this with a simpler environment where we can actually test if it finds a solution
env = gym.make('Pendulum-v0')
np.random.seed(123)
env.seed(123)
random.seed(123)
nb_actions = env.action_space.shape[0]
actor = Sequential()
actor.add(Flatten(input_shape=(1,) + env.observation_space.shape))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(nb_actions))
actor.add(Activation('linear'))
action_input = Input(shape=(nb_actions,), name='action_input')
observation_input = Input(shape=(1,) + env.observation_space.shape, name='observation_input')
flattened_observation = Flatten()(observation_input)
x = Concatenate()([action_input, flattened_observation])
x = Dense(16)(x)
x = Activation('relu')(x)
x = Dense(1)(x)
x = Activation('linear')(x)
critic = Model(inputs=[action_input, observation_input], outputs=x)
memory = SequentialMemory(limit=1000, window_length=1)
random_process = OrnsteinUhlenbeckProcess(theta=.15, mu=0., sigma=.3)
agent = DDPGAgent(nb_actions=nb_actions, actor=actor, critic=critic, critic_action_input=action_input,
memory=memory, nb_steps_warmup_critic=50, nb_steps_warmup_actor=50,
random_process=random_process, gamma=.99, target_model_update=1e-3)
agent.compile([Adam(lr=1e-3), Adam(lr=1e-3)])
agent.fit(env, nb_steps=400, visualize=False, verbose=0, nb_max_episode_steps=100)
h = agent.test(env, nb_episodes=2, visualize=False, nb_max_episode_steps=100)
# TODO: evaluate history
def CNN(seq_length, length, input_size, feature_maps, kernels, x):
concat_input = []
for feature_map, kernel in zip(feature_maps, kernels):
reduced_l = length - kernel + 1
conv = Conv2D(feature_map, (1, kernel), activation='tanh', data_format="channels_last")(x)
maxp = MaxPooling2D((1, reduced_l), data_format="channels_last")(conv)
concat_input.append(maxp)
x = Concatenate()(concat_input)
x = Reshape((seq_length, sum(feature_maps)))(x)
return x
def CNN(seq_length, length, input_size, feature_maps, kernels, x):
concat_input = []
for feature_map, kernel in zip(feature_maps, kernels):
reduced_l = length - kernel + 1
conv = Conv2D(feature_map, (1, kernel), activation='tanh', data_format="channels_last")(x)
maxp = MaxPooling2D((1, reduced_l), data_format="channels_last")(conv)
concat_input.append(maxp)
con = Concatenate()(concat_input)
con = Reshape((seq_length, sum(feature_maps)))(con)
return con
def convolutional_model_deepcsv(Inputs,nclasses,nregclasses,dropoutRate=-1):
cpf=Inputs[1]
vtx=Inputs[2]
cpf = Convolution1D(64, 1, kernel_initializer='lecun_uniform', activation='relu', name='cpf_conv0')(cpf)
cpf = Dropout(dropoutRate)(cpf)
cpf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu', name='cpf_conv1')(cpf)
cpf = Dropout(dropoutRate)(cpf)
cpf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu', name='cpf_conv2')(cpf)
cpf = Dropout(dropoutRate)(cpf)
cpf = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu' , name='cpf_conv3')(cpf)
vtx = Convolution1D(64, 1, kernel_initializer='lecun_uniform', activation='relu', name='vtx_conv0')(vtx)
vtx = Dropout(dropoutRate)(vtx)
vtx = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu', name='vtx_conv1')(vtx)
vtx = Dropout(dropoutRate)(vtx)
vtx = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu', name='vtx_conv2')(vtx)
vtx = Dropout(dropoutRate)(vtx)
vtx = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu', name='vtx_conv3')(vtx)
cpf=Flatten()(cpf)
vtx=Flatten()(vtx)
x = Concatenate()( [Inputs[0],cpf,vtx ])
x = block_deepFlavourDense(x,dropoutRate)
predictions = Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform',name='ID_pred')(x)
model = Model(inputs=Inputs, outputs=predictions)
return model
def convolutional_model_broad(Inputs,nclasses,nregclasses,dropoutRate=-1):
"""
reference 1x1 convolutional model for 'deepFlavour', as for DPS note
"""
cpf,npf,vtx = block_deepFlavourConvolutions(charged=Inputs[1],
neutrals=Inputs[2],
vertices=Inputs[3],
dropoutRate=dropoutRate)
cpf = LSTM(150,go_backwards=True,implementation=2, name='cpf_lstm')(cpf)
cpf = Dropout(dropoutRate)(cpf)
npf = LSTM(50,go_backwards=True,implementation=2, name='npf_lstm')(npf)
npf = Dropout(dropoutRate)(npf)
vtx = LSTM(50,go_backwards=True,implementation=2, name='vtx_lstm')(vtx)
vtx = Dropout(dropoutRate)(vtx)
image = block_SchwartzImage(image=Inputs[4],dropoutRate=dropoutRate,active=False)
x = Concatenate()( [Inputs[0],cpf,npf,vtx,image ])
x = block_deepFlavourDense(x,dropoutRate)
predictions = Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform',name='ID_pred')(x)
model = Model(inputs=Inputs, outputs=predictions)
return model
def convolutional_model_broad_map(Inputs,nclasses,nregclasses,dropoutRate=-1):
"""
reference 1x1 convolutional model for 'deepFlavour'
"""
cpf,npf,vtx = block_deepFlavourConvolutions(charged=Inputs[1],
neutrals=Inputs[2],
vertices=Inputs[3],
dropoutRate=dropoutRate)
cpf = LSTM(150,go_backwards=True,implementation=2, name='cpf_lstm')(cpf)
cpf = Dropout(dropoutRate)(cpf)
npf = LSTM(50,go_backwards=True,implementation=2, name='npf_lstm')(npf)
npf = Dropout(dropoutRate)(npf)
vtx = LSTM(50,go_backwards=True,implementation=2, name='vtx_lstm')(vtx)
vtx = Dropout(dropoutRate)(vtx)
image = block_SchwartzImage(image=Inputs[4],dropoutRate=dropoutRate)
x = Concatenate()( [Inputs[0],cpf,npf,vtx,image ])
x = block_deepFlavourDense(x,dropoutRate)
predictions = Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform',name='ID_pred')(x)
model = Model(inputs=Inputs, outputs=predictions)
return model
def convolutional_model_broad_reg(Inputs,nclasses,nregclasses,dropoutRate=-1):
"""
the inputs are really not working as they are. need a reshaping well before
"""
cpf,npf,vtx = block_deepFlavourConvolutions(charged=Inputs[1],
neutrals=Inputs[2],
vertices=Inputs[3],
dropoutRate=dropoutRate)
cpf = LSTM(150,go_backwards=True,implementation=2, name='cpf_lstm')(cpf)
cpf = Dropout(dropoutRate)(cpf)
npf = LSTM(50,go_backwards=True,implementation=2, name='npf_lstm')(npf)
npf = Dropout(dropoutRate)(npf)
vtx = LSTM(50,go_backwards=True,implementation=2, name='vtx_lstm')(vtx)
vtx = Dropout(dropoutRate)(vtx)
x = Concatenate()( [Inputs[0],cpf,npf,vtx,Inputs[4] ])
x = block_deepFlavourDense(x,dropoutRate)
predictions = [Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform',name='ID_pred')(x),
Dense(nregclasses, activation='linear',kernel_initializer='ones',name='E_pred')(x)]
model = Model(inputs=Inputs, outputs=predictions)
return model
def convolutional_model_ConvCSV(Inputs,nclasses,nregclasses,dropoutRate=0.25):
"""
Inputs similar to 2016 training, but with covolutional layers on each track and sv
"""
a = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1])
a = Dropout(dropoutRate)(a)
a = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(a)
a = Dropout(dropoutRate)(a)
a = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(a)
a = Dropout(dropoutRate)(a)
a=Flatten()(a)
c = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[2])
c = Dropout(dropoutRate)(c)
c = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(c)
c = Dropout(dropoutRate)(c)
c = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(c)
c = Dropout(dropoutRate)(c)
c=Flatten()(c)
x = Concatenate()( [Inputs[0],a,c] )
x = Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x = Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x = Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x = Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
predictions = Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform')(x)
model = Model(inputs=Inputs, outputs=predictions)
return model
def test_delete_channels_merge_concatenate(channel_index, data_format):
# This should test that the output is the correct shape so it should pass
# into a Dense layer rather than a Conv layer.
# The weighted layer is the previous layer,
# Create model
if data_format == 'channels_first':
axis = 1
elif data_format == 'channels_last':
axis = -1
else:
raise ValueError
input_shape = list(random.randint(10, 20, size=3))
input_1 = Input(shape=input_shape)
input_2 = Input(shape=input_shape)
x = Conv2D(3, [3, 3], data_format=data_format, name='conv_1')(input_1)
y = Conv2D(3, [3, 3], data_format=data_format, name='conv_2')(input_2)
x = Concatenate(axis=axis, name='cat_1')([x, y])
x = Flatten()(x)
main_output = Dense(5, name='dense_1')(x)
model = Model(inputs=[input_1, input_2], outputs=main_output)
old_w = model.get_layer('dense_1').get_weights()
# Delete channels
layer = model.get_layer('cat_1')
del_layer = model.get_layer('conv_1')
surgeon = Surgeon(model, copy=True)
surgeon.add_job('delete_channels', del_layer, channels=channel_index)
new_model = surgeon.operate()
new_w = new_model.get_layer('dense_1').get_weights()
# Calculate next layer's correct weights
flat_sz = np.prod(layer.get_output_shape_at(0)[1:])
channel_count = getattr(del_layer, utils.get_channels_attr(del_layer))
channel_index = [i % channel_count for i in channel_index]
if data_format == 'channels_first':
delete_indices = [x * flat_sz // 2 // channel_count + i for x in
channel_index
for i in range(0, flat_sz // 2 // channel_count, )]
elif data_format == 'channels_last':
delete_indices = [x + i for i in range(0, flat_sz, channel_count*2)
for x in channel_index]
else:
raise ValueError
correct_w = model.get_layer('dense_1').get_weights()
correct_w[0] = np.delete(correct_w[0], delete_indices, axis=0)
assert weights_equal(correct_w, new_w)
def LSTMCNN(opt):
# opt.seq_length = number of time steps (words) in each batch
# opt.rnn_size = dimensionality of hidden layers
# opt.num_layers = number of layers
# opt.dropout = dropout probability
# opt.word_vocab_size = num words in the vocab
# opt.word_vec_size = dimensionality of word embeddings
# opt.char_vocab_size = num chars in the character vocab
# opt.char_vec_size = dimensionality of char embeddings
# opt.feature_maps = table of feature map sizes for each kernel width
# opt.kernels = table of kernel widths
# opt.length = max length of a word
# opt.use_words = 1 if use word embeddings, otherwise not
# opt.use_chars = 1 if use char embeddings, otherwise not
# opt.highway_layers = number of highway layers to use, if any
# opt.batch_size = number of sequences in each batch
if opt.use_words:
word = Input(batch_shape=(opt.batch_size, opt.seq_length), dtype='int32', name='word')
word_vecs = Embedding(opt.word_vocab_size, opt.word_vec_size, input_length=opt.seq_length)(word)
if opt.use_chars:
chars = Input(batch_shape=(opt.batch_size, opt.seq_length, opt.max_word_l), dtype='int32', name='chars')
chars_embedding = TimeDistributed(Embedding(opt.char_vocab_size, opt.char_vec_size, name='chars_embedding'))(chars)
cnn = CNN(opt.seq_length, opt.max_word_l, opt.char_vec_size, opt.feature_maps, opt.kernels, chars_embedding)
if opt.use_words:
x = Concatenate()([cnn, word_vecs])
inputs = [chars, word]
else:
x = cnn
inputs = chars
else:
x = word_vecs
inputs = word
if opt.batch_norm:
x = BatchNormalization()(x)
for l in range(opt.highway_layers):
x = TimeDistributed(Highway(activation='relu'))(x)
for l in range(opt.num_layers):
x = LSTM(opt.rnn_size, activation='tanh', recurrent_activation='sigmoid', return_sequences=True, stateful=True)(x)
if opt.dropout > 0:
x = Dropout(opt.dropout)(x)
output = TimeDistributed(Dense(opt.word_vocab_size, activation='softmax'))(x)
model = sModel(inputs=inputs, outputs=output)
model.summary()
optimizer = sSGD(lr=opt.learning_rate, clipnorm=opt.max_grad_norm, scale=float(opt.seq_length))
model.compile(loss='sparse_categorical_crossentropy', optimizer=optimizer)
return model
def __init__(self, word_index, embedding_matrix):
embedding_layer_q = Embedding(len(word_index) + 1,
EMBEDDING_DIM,
weights=[embedding_matrix],
input_length=MAX_SEQUENCE_LENGTH_Q,
trainable=False)
embedding_layer_a = Embedding(len(word_index) + 1,
EMBEDDING_DIM,
weights=[embedding_matrix],
input_length=MAX_SEQUENCE_LENGTH_A,
trainable=False)
question = Input(shape=(MAX_SEQUENCE_LENGTH_Q,), dtype='int32', name='question')
answer = Input(shape=(MAX_SEQUENCE_LENGTH_A,), dtype='int32', name='answer')
embedded_question = embedding_layer_q(question)
embedded_answer = embedding_layer_a(answer)
conv_blocksA = []
conv_blocksQ = []
for sz in [3,5]:
conv = Convolution1D(filters=20,
kernel_size=sz,
padding="valid",
activation="relu",
strides=1)(embedded_answer)
conv = MaxPooling1D(pool_size=2)(conv)
conv = Flatten()(conv)
conv_blocksA.append(conv)
for sz in [5,7, 9]:
conv = Convolution1D(filters=20,
kernel_size=sz,
padding="valid",
activation="relu",
strides=1)(embedded_question)
conv = MaxPooling1D(pool_size=3)(conv)
conv = Flatten()(conv)
conv_blocksQ.append(conv)
z = Concatenate()(conv_blocksA + conv_blocksQ)
z = Dropout(0.5)(z)
z = Dense(100, activation="relu")(z)
softmax_c_q = Dense(2, activation='softmax')(z)
self.model = Model([question, answer], softmax_c_q)
opt = Nadam()
self.model.compile(loss='categorical_crossentropy',
optimizer=opt,
metrics=['acc'])
def model_deepFlavourNoNeutralReference(Inputs,nclasses,nregclasses,dropoutRate=0.1):
"""
reference 1x1 convolutional model for 'deepFlavour'
with recurrent layers and batch normalisation
standard dropout rate it 0.1
should be trained for flavour prediction first. afterwards, all layers can be fixed
that do not include 'regression' and the training can be repeated focusing on the regression part
(check function fixLayersContaining with invert=True)
"""
globalvars = BatchNormalization(momentum=0.6,name='globals_input_batchnorm') (Inputs[0])
cpf = BatchNormalization(momentum=0.6,name='cpf_input_batchnorm') (Inputs[1])
vtx = BatchNormalization(momentum=0.6,name='vtx_input_batchnorm') (Inputs[2])
ptreginput = BatchNormalization(momentum=0.6,name='reg_input_batchnorm') (Inputs[3])
cpf, vtx = block_deepFlavourBTVConvolutions(
charged=cpf,
vertices=vtx,
dropoutRate=dropoutRate,
active=True,
batchnorm=True
)
#
cpf = LSTM(150,go_backwards=True,implementation=2, name='cpf_lstm')(cpf)
cpf=BatchNormalization(momentum=0.6,name='cpflstm_batchnorm')(cpf)
cpf = Dropout(dropoutRate)(cpf)
vtx = LSTM(50,go_backwards=True,implementation=2, name='vtx_lstm')(vtx)
vtx=BatchNormalization(momentum=0.6,name='vtxlstm_batchnorm')(vtx)
vtx = Dropout(dropoutRate)(vtx)
x = Concatenate()( [globalvars,cpf,vtx ])
x = block_deepFlavourDense(x,dropoutRate,active=True,batchnorm=True,batchmomentum=0.6)
flavour_pred=Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform',name='ID_pred')(x)
reg = Concatenate()( [flavour_pred, ptreginput ] )
reg_pred=Dense(nregclasses, activation='linear',kernel_initializer='ones',name='regression_pred',trainable=True)(reg)
predictions = [flavour_pred,reg_pred]
model = Model(inputs=Inputs, outputs=predictions)
return model
def model_deepFlavourReference(Inputs,nclasses,nregclasses,dropoutRate=0.1,momentum=0.6):
"""
reference 1x1 convolutional model for 'deepFlavour'
with recurrent layers and batch normalisation
standard dropout rate it 0.1
should be trained for flavour prediction first. afterwards, all layers can be fixed
that do not include 'regression' and the training can be repeated focusing on the regression part
(check function fixLayersContaining with invert=True)
"""
globalvars = BatchNormalization(momentum=momentum,name='globals_input_batchnorm') (Inputs[0])
cpf = BatchNormalization(momentum=momentum,name='cpf_input_batchnorm') (Inputs[1])
npf = BatchNormalization(momentum=momentum,name='npf_input_batchnorm') (Inputs[2])
vtx = BatchNormalization(momentum=momentum,name='vtx_input_batchnorm') (Inputs[3])
ptreginput = BatchNormalization(momentum=momentum,name='reg_input_batchnorm') (Inputs[4])
cpf,npf,vtx = block_deepFlavourConvolutions(charged=cpf,
neutrals=npf,
vertices=vtx,
dropoutRate=dropoutRate,
active=True,
batchnorm=True, batchmomentum=momentum)
#
cpf = LSTM(150,go_backwards=True,implementation=2, name='cpf_lstm')(cpf)
cpf=BatchNormalization(momentum=momentum,name='cpflstm_batchnorm')(cpf)
cpf = Dropout(dropoutRate)(cpf)
npf = LSTM(50,go_backwards=True,implementation=2, name='npf_lstm')(npf)
npf=BatchNormalization(momentum=momentum,name='npflstm_batchnorm')(npf)
npf = Dropout(dropoutRate)(npf)
vtx = LSTM(50,go_backwards=True,implementation=2, name='vtx_lstm')(vtx)
vtx=BatchNormalization(momentum=momentum,name='vtxlstm_batchnorm')(vtx)
vtx = Dropout(dropoutRate)(vtx)
x = Concatenate()( [globalvars,cpf,npf,vtx ])
x = block_deepFlavourDense(x,dropoutRate,active=True,batchnorm=True,batchmomentum=momentum)
flavour_pred=Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform',name='ID_pred')(x)
reg = Concatenate()( [flavour_pred, ptreginput ] )
reg_pred=Dense(nregclasses, activation='linear',kernel_initializer='ones',name='regression_pred',trainable=True)(reg)
predictions = [flavour_pred,reg_pred]
model = Model(inputs=Inputs, outputs=predictions)
return model
def convolutional_model_lessbroad(Inputs,nclasses,nregclasses,dropoutRate=-1):
"""
the inputs are really not working as they are. need a reshaping well before
"""
#gl = Dense(8, activation='relu',kernel_initializer='lecun_uniform',input_shape=Inputshapes[0])(Inputs[0])
#gl = Dense(8, activation='relu',kernel_initializer='lecun_uniform')(gl)
#gl = Dense(8, activation='relu',kernel_initializer='lecun_uniform')(gl)
cpf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1])
cpf = Dropout(dropoutRate)(cpf)
cpf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf)
cpf = Dropout(dropoutRate)(cpf)
cpf = Convolution1D(16, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf)
cpf = Dropout(dropoutRate)(cpf)
cpf = Flatten()(cpf)
npf = Convolution1D(16, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[2])
npf = Dropout(dropoutRate)(npf)
npf = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(npf)
npf = Dropout(dropoutRate)(npf)
npf = Flatten()(npf)
vtx = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[3])
vtx = Dropout(dropoutRate)(vtx)
vtx = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx)
vtx = Dropout(dropoutRate)(vtx)
vtx = Convolution1D(16, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx)
vtx = Dropout(dropoutRate)(vtx)
vtx = Flatten()(vtx)
x = Concatenate()( [Inputs[0],cpf,npf,vtx ] )
x = Dropout(dropoutRate)(x)
x= Dense(600, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
predictions = Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform')(x)
model = Model(inputs=Inputs, outputs=predictions)
return model