Exemplo n.º 1
0
    def test_text_classification_demo(self):
        with patch_data_loader():
            with tempfile.TemporaryDirectory() as temp_dir:
                # Use cached training data if exists.
                data_dir = text_classification_demo.download_demo_data(
                    cache_dir=get_cache_dir(),
                    file_hash='9f81648d4199384278b86e315dac217c')

                tflite_filename = os.path.join(temp_dir, 'model.tflite')
                label_filename = os.path.join(temp_dir, 'label.txt')
                vocab_filename = os.path.join(temp_dir, 'vocab.txt')
                # TODO(b/150597348): Bert model is out of memory when export to tflite.
                # Changed to a smaller bert models like mobilebert later for unittest.
                text_classification_demo.run(data_dir,
                                             tflite_filename,
                                             label_filename,
                                             vocab_filename,
                                             spec='average_word_vec',
                                             epochs=1,
                                             batch_size=1)

                self.assertTrue(tf.io.gfile.exists(tflite_filename))
                self.assertGreater(os.path.getsize(tflite_filename), 0)

                self.assertTrue(tf.io.gfile.exists(label_filename))
                self.assertGreater(os.path.getsize(label_filename), 0)

                self.assertTrue(tf.io.gfile.exists(vocab_filename))
                self.assertGreater(os.path.getsize(vocab_filename), 0)
Exemplo n.º 2
0
  def text_classification(self,
                          data_dir,
                          tflite_filename,
                          label_filename,
                          vocab_filename,
                          spec='bert',
                          **kwargs):
    r"""Run text classification.

    Args:
      data_dir: str, input directory of training data. (required)
      tflite_filename: str, output path to export tflite file. (required)
      label_filename: str, output path to export label file. (required)
      vocab_filename: str, output path to export vocab file. (required)
      spec: str, model_name. Valid: {MODELS}, default: bert.
      **kwargs: --epochs: int, epoch num to run. More: see `create` function.
    """
    # Convert types
    data_dir = str(data_dir)
    tflite_filename = str(tflite_filename)
    label_filename = str(label_filename)
    vocab_filename = str(vocab_filename)

    text_classification_demo.run(data_dir, tflite_filename, label_filename,
                                 vocab_filename, spec, **kwargs)
Exemplo n.º 3
0
Arquivo: cli.py Projeto: bqi1/PoseNet
  def text_classification(self,
                          data_dir,
                          export_dir,
                          spec='mobilebert_classifier',
                          **kwargs):
    r"""Run text classification.

    Args:
      data_dir: str, input directory of training data. (required)
      export_dir: str, output directory to export files. (required)
      spec: str, model_name. Valid: {MODELS}, default: mobilebert_classifier.
      **kwargs: --epochs: int, epoch num to run. More: see `create` function.
    """
    # Convert types
    data_dir = str(data_dir)
    export_dir = str(export_dir)
    text_classification_demo.run(data_dir, export_dir, spec, **kwargs)