def build(self, hp): maxnorm = hp.Choice('maxnorm', values=self.hyperparam['maxnorm']) resnet_model = Resnet(input_shape=(self.seqlen, self.channels), norm_max=maxnorm) if self.pretrained_weights is not None: resnet_model.set_weights(self.pretrained_weights) inp = Input(shape=(self.seqlen, self.channels)) enc_inp = resnet_model(inp) dense_units = hp.Int('preclassification', min_value = self.hyperparam['dense_units']['min'],\ max_value = self.hyperparam['dense_units']['max'], step = self.hyperparam['dense_units']['step']) dense_out = Dense(units = dense_units, activation='relu', kernel_constraint=MaxNorm(maxnorm,axis=[0,1]), bias_constraint=MaxNorm(maxnorm,axis=0), kernel_initializer=glorot_uniform(seed=0))(enc_inp) dense_out = Dropout(rate=hp.Choice('dropout', values = self.hyperparam['dropout']))(dense_out) output = Dense(self.num_classes, activation='softmax', kernel_constraint=MaxNorm(maxnorm,axis=[0,1]), bias_constraint=MaxNorm(maxnorm,axis=0), kernel_initializer=glorot_uniform(seed=0))(dense_out) model = Model(inputs=inp, outputs=output) model.compile(optimizer=Adam(lr=hp.Choice('lr', values = self.hyperparam['lr'])), loss=focal_loss(), metrics=['accuracy', macro_f1]) return model
def main(argv): infile = argv[0] outfile = argv[1] seqlen = 1500 channels = 6 maxnorm = 20.0 # Create model resnet_model = Resnet(input_shape=(seqlen, channels), norm_max=maxnorm) samp1 = Input(shape=(seqlen, channels)) enc_samp1 = resnet_model(samp1) samp2 = Input(shape=(seqlen, channels)) enc_samp2 = resnet_model(samp2) diff_layer = Lambda(lambda tensors: K.abs(tensors[0] - tensors[1])) diff_enc = diff_layer([enc_samp1, enc_samp2]) dense_out = Dense(50, activation='relu', kernel_constraint=MaxNorm(maxnorm, axis=[0, 1]), bias_constraint=MaxNorm(maxnorm, axis=0), kernel_initializer=glorot_uniform(seed=0))(diff_enc) dense_out = Dropout(rate=0.2)(dense_out) output = Dense(1, activation='sigmoid', kernel_constraint=MaxNorm(maxnorm, axis=[0, 1]), bias_constraint=MaxNorm(maxnorm, axis=0), kernel_initializer=glorot_uniform(seed=0))(dense_out) model = Model(inputs=[samp1, samp2], outputs=output) model.load_weights(infile) for layer in model.layers: if layer.name == "model": resnet_model.set_weights(layer.get_weights()) resnet_model.save_weights(outfile)