Esempio n. 1
0
    def build_model(self):
        opts = self.opts
        log = self.log

        output_names = dat.get_output_names(opts.train_files[0],
                                            regex=opts.output_names,
                                            nb_key=opts.nb_output)
        if not output_names:
            raise ValueError('No outputs found!')

        dna_model = None
        if opts.dna_model:
            dna_model = self.build_dna_model()

        cpg_model = None
        if opts.cpg_model:
            cpg_model = self.build_cpg_model()

        if dna_model is not None and cpg_model is not None:
            log.info('Joining models ...')
            joint_model_builder = mod.joint.get(opts.joint_model)(
                l1_decay=opts.l1_decay,
                l2_decay=opts.l2_decay,
                dropout=opts.dropout)
            stem = joint_model_builder([dna_model, cpg_model])
            stem.name = '_'.join([stem.name, dna_model.name, cpg_model.name])
        elif dna_model is not None:
            stem = dna_model
        elif cpg_model is not None:
            stem = cpg_model
        else:
            log.info('Loading existing model ...')
            stem = mod.load_model(opts.model_files, log=log.info)
            if sorted(output_names) == sorted(stem.output_names):
                return stem
            log.info('Removing existing output layers ...')
            remove_outputs(stem)

        outputs = mod.add_output_layers(stem.outputs, output_names)
        model = Model(input=stem.inputs, output=outputs, name=stem.name)
        return model
Esempio n. 2
0
    def build_model(self):
        opts = self.opts
        log = self.log

        output_names = dat.get_output_names(opts.train_files[0],
                                            regex=opts.output_names,
                                            nb_key=opts.nb_output)
        if not output_names:
            raise ValueError('No outputs found!')

        dna_model = None
        if opts.dna_model:
            dna_model = self.build_dna_model()

        cpg_model = None
        if opts.cpg_model:
            cpg_model = self.build_cpg_model()

        if dna_model is not None and cpg_model is not None:
            log.info('Joining models ...')
            joint_model_builder = mod.joint.get(opts.joint_model)(
                l1_decay=opts.l1_decay,
                l2_decay=opts.l2_decay,
                dropout=opts.dropout)
            stem = joint_model_builder([dna_model, cpg_model])
            stem.name = '_'.join([stem.name, dna_model.name, cpg_model.name])
        elif dna_model is not None:
            stem = dna_model
        elif cpg_model is not None:
            stem = cpg_model
        else:
            log.info('Loading existing model ...')
            stem = mod.load_model(opts.model_files, log=log.info)
            if sorted(output_names) == sorted(stem.output_names):
                return stem
            log.info('Removing existing output layers ...')
            remove_outputs(stem)

        outputs = mod.add_output_layers(stem.outputs[0], output_names)
        model = Model(inputs=stem.inputs, outputs=outputs, name=stem.name)
        return model