예제 #1
0
파일: elmo.py 프로젝트: RileyShe/DeepPavlov
    def elmo_export(self, epoch: Optional[int] = None) -> None:
        """
        Dump the trained weights from a model to a HDF5 file and export a TF-Hub module.
        """
        if hasattr(self, 'sess'):
            self.sess.close()
        path = self.save_path
        if epoch:
            from_path = path.parent / self.epoch_save_path / str(epoch) / path.parts[-1]
            weights_to_path = path.parent / self.dumps_save_path / f'weights_epoch_n_{epoch}.hdf5'
            tf_hub_to_path = path.parent / self.tf_hub_save_path / f'tf_hub_model_epoch_n_{epoch}'
            from_path.resolve()
            weights_to_path.resolve()
            tf_hub_to_path.resolve()
            log.info(f'[exporting {epoch} epoch]')
        else:
            from_path = path
            weights_to_path = path.parent / self.dumps_save_path / 'weights.hdf5'
            tf_hub_to_path = path.parent / self.tf_hub_save_path / 'tf_hub_model'

        weights_to_path.parent.mkdir(parents=True, exist_ok=True)
        tf_hub_to_path.parent.mkdir(parents=True, exist_ok=True)

        # Check presence of the model files
        if tf.train.checkpoint_exists(str(from_path)):
            dump_weights(from_path.parent, weights_to_path, self.permanent_options)

            options = copy.deepcopy(self.permanent_options)
            options['char_cnn']['n_characters'] = 262
            export2hub(weights_to_path, tf_hub_to_path, options)
예제 #2
0
    def elmo_export(self, epoch: Optional[int] = None) -> None:
        """
        Dump the trained weights from a model to a HDF5 file and export a TF-Hub module.
        """
        if hasattr(self, 'sess'):
            self.sess.close()
        path = self.save_path
        if epoch:
            from_path = path.parent / self.epoch_save_path / str(
                epoch) / path.parts[-1]
            weights_to_path = path.parent / self.dumps_save_path / f'weights_epoch_n_{epoch}.hdf5'
            tf_hub_to_path = path.parent / self.tf_hub_save_path / f'tf_hub_model_epoch_n_{epoch}'
            from_path.resolve()
            weights_to_path.resolve()
            tf_hub_to_path.resolve()
            log.info(f'[exporting {epoch} epoch]')
        else:
            from_path = path
            weights_to_path = path.parent / self.dumps_save_path / 'weights.hdf5'
            tf_hub_to_path = path.parent / self.tf_hub_save_path / 'tf_hub_model'

        weights_to_path.parent.mkdir(parents=True, exist_ok=True)
        tf_hub_to_path.parent.mkdir(parents=True, exist_ok=True)

        # Check presence of the model files
        if tf.train.checkpoint_exists(str(from_path)):
            dump_weights(from_path.parent, weights_to_path,
                         self.permanent_options)

            options = copy.deepcopy(self.permanent_options)
            options['char_cnn']['n_characters'] = 262
            export2hub(weights_to_path, tf_hub_to_path, options)