def test_efficientnetlite0_model(self):
     model = image_classifier.create(self.train_data,
                                     model_spec.efficientnet_lite0_spec,
                                     epochs=2,
                                     batch_size=4,
                                     shuffle=True)
     self._test_accuracy(model)
     self._test_export_to_tflite(model)
 def test_efficientnetlite0_model_with_model_maker_retraining_lib(self):
     model = image_classifier.create(self.train_data,
                                     model_spec.efficientnet_lite0_spec(),
                                     epochs=1,
                                     batch_size=1,
                                     shuffle=True,
                                     use_hub_library=False)
     self._test_accuracy(model)
     self._test_export_to_tflite(model)
Exemple #3
0
 def test_resnet_50_model(self):
     model = image_classifier.create(self.train_data,
                                     mef.ModelExportFormat.TFLITE,
                                     model_spec.resnet_50_spec,
                                     epochs=2,
                                     batch_size=4,
                                     shuffle=True)
     self._test_accuracy(model)
     self._test_export_to_tflite(model)
 def test_resnet_50_model(self):
     model = image_classifier.create(self.train_data,
                                     model_spec.resnet_50_spec(),
                                     epochs=1,
                                     batch_size=1,
                                     shuffle=True)
     self._test_accuracy(model)
     self._test_export_to_tflite(model)
     self._test_export_to_tflite_quantized(model, self.train_data)
     self._test_export_to_tflite_with_metadata(model)
 def test_efficientnetlite0_model(self):
     model = image_classifier.create(self.train_data,
                                     model_spec.efficientnet_lite0_spec(),
                                     epochs=1,
                                     batch_size=1,
                                     shuffle=True)
     self._test_accuracy(model)
     self._test_export_to_tflite(model)
     self._test_export_to_tflite_quantized(model, self.train_data)
     self._test_export_to_tflite_with_metadata(
         model, expected_json_file='efficientnet_lite0_metadata.json')
Exemple #6
0
 def test_mobilenetv2_model(self):
     model = image_classifier.create(self.train_data,
                                     mef.ModelExportFormat.TFLITE,
                                     model_spec.mobilenet_v2_spec,
                                     epochs=2,
                                     batch_size=4,
                                     shuffle=True)
     self._test_accuracy(model)
     self._test_export_to_tflite(model)
     self._test_predict_top_k(model)
     self._test_export_to_tflite_quantized(model, self.train_data)
 def test_mobilenetv2_model(self):
     model = image_classifier.create(self.train_data,
                                     model_spec.mobilenet_v2_spec(),
                                     epochs=1,
                                     batch_size=1,
                                     shuffle=True)
     self._test_accuracy(model)
     self._test_predict_top_k(model)
     self._test_export_to_tflite(model)
     self._test_export_to_tflite_quantized(model, self.train_data)
     self._test_export_to_tflite_with_metadata(model)
     self._test_export_to_saved_model(model)
     self._test_export_labels(model)
def run(data_dir, export_dir, spec='efficientnet_lite0', **kwargs):
    """Runs demo."""
    spec = model_spec.get(spec)
    data = ImageClassifierDataLoader.from_folder(data_dir)
    train_data, rest_data = data.split(0.8)
    validation_data, test_data = rest_data.split(0.5)

    model = image_classifier.create(train_data,
                                    model_spec=spec,
                                    validation_data=validation_data,
                                    **kwargs)

    _, acc = model.evaluate(test_data)
    print('Test accuracy: %f' % acc)
    model.export(export_dir)
def main(_):
    logging.set_verbosity(logging.INFO)

    image_path = tf.keras.utils.get_file(
        'flower_photos',
        'https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz',
        untar=True)
    data = ImageClassifierDataLoader.from_folder(image_path)
    train_data, rest_data = data.split(0.8)
    validation_data, test_data = rest_data.split(0.5)

    model = image_classifier.create(
        train_data,
        model_export_format=ModelExportFormat.TFLITE,
        model_spec=efficientnet_b0_spec,
        validation_data=validation_data)

    _, acc = model.evaluate(test_data)
    print('Test accuracy: %f' % acc)

    model.export(FLAGS.tflite_filename, FLAGS.label_filename)
def run(data_dir,
        tflite_filename,
        label_filename,
        spec='efficientnet_b0',
        **kwargs):
  """Runs demo."""
  spec = model_spec.get(spec)
  data = ImageClassifierDataLoader.from_folder(data_dir)
  train_data, rest_data = data.split(0.8)
  validation_data, test_data = rest_data.split(0.5)

  model = image_classifier.create(
      train_data,
      model_export_format=ModelExportFormat.TFLITE,
      model_spec=spec,
      validation_data=validation_data,
      **kwargs)

  _, acc = model.evaluate(test_data)
  print('Test accuracy: %f' % acc)
  model.export(tflite_filename, label_filename)
def run(data_dir, export_dir, spec='efficientnet_lite0', **kwargs):
    """Runs demo."""
    spec = model_spec.get(spec)
    data = ImageClassifierDataLoader.from_folder(data_dir)
    train_data, rest_data = data.split(0.8)
    validation_data, test_data = rest_data.split(0.5)

    model = image_classifier.create(train_data,
                                    model_spec=spec,
                                    validation_data=validation_data,
                                    **kwargs)

    _, acc = model.evaluate(test_data)
    print('Test accuracy: %f' % acc)

    # Exports to TFLite and SavedModel, with label file.
    export_format = [
        ExportFormat.TFLITE,
        ExportFormat.SAVED_MODEL,
    ]
    model.export(export_dir, export_format=export_format)
#from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf

from tensorflow_examples.lite.model_maker.core.data_util.image_dataloader import ImageClassifierDataLoader
from tensorflow_examples.lite.model_maker.core.task import image_classifier
from tensorflow_examples.lite.model_maker.core.task.model_spec import ImageModelSpec

data = ImageClassifierDataLoader.from_folder('nsfw/')
train_data, test_data = data.split(0.8)
model = image_classifier.create(train_data)
loss, accuracy = model.evaluate(test_data)
model.export('nsfw_classifier.tflite', 'nsfw_label.txt')
Exemple #13
0
 def test_mobilenetv2_model_create_v1_incompatible(self):
   with self.assertRaisesRegex(ValueError, 'Incompatible versions'):
     _ = image_classifier.create(self.train_data,
                                 model_spec.mobilenet_v2_spec())
Exemple #14
0
 def test_efficientnetlite0_model_without_training(self):
   model = image_classifier.create(
       self.train_data, model_spec.efficientnet_lite0_spec(), do_train=False)
   self._test_accuracy(model, threshold=0.0)
   self._test_export_to_tflite(model, threshold=0.0)
from tensorflow_examples.lite.model_maker.core.data_util.image_dataloader import ImageClassifierDataLoader
from tensorflow_examples.lite.model_maker.core.task import image_classifier
from tensorflow_examples.lite.model_maker.core.task import model_spec as ms

data_path = r"/home/AlgorithmicGroup/yw/workshop/antiface/data/clean_data"
# 这个path指图像数据文件夹路径,其下面按类别分为多个子文件夹
data = ImageClassifierDataLoader.from_folder(data_path)
train_data, test_data = data.split(0.92)

print("done data load.")

model = image_classifier.create(train_data,
                                model_spec=ms.efficientnet_lite0_spec,
                                shuffle=True,
                                validation_data=test_data,
                                batch_size=32,
                                epochs=20,
                                train_whole_model=False,
                                dropout_rate=0.2,
                                learning_rate=0.005,
                                momentum=0.9)
#指定模型为efficientnet_lite0,可以换成其他的
"""
def get_default_hparams():
  return HParams(
      train_epochs=5,
      do_fine_tuning=False,(train_whole_model)
      batch_size=32,
      learning_rate=0.005,
      momentum=0.9,
      dropout_rate=0.2)
"""
Exemple #16
0
import tensorflow as tf

from tensorflow_examples.lite.model_maker.core.data_util.image_dataloader import ImageClassifierDataLoader
from tensorflow_examples.lite.model_maker.core.task import image_classifier
from tensorflow_examples.lite.model_maker.core.task import model_spec as ms

data_path = "D:/Data/clothes_style/data/DeepFashion/classes7/data_val"
# 这个path指图像数据文件夹路径,其下面按类别分为多个子文件夹
data = ImageClassifierDataLoader.from_folder(data_path)
train_data, test_data = data.split(0.9)

print("done data load.")

model = image_classifier.create(train_data,
                                model_spec=ms.efficientnet_lite0_spec)
#指定模型为efficientnet_lite0,可以换成其他的

loss, accuracy = model.evaluate(test_data)
#训练过程也会打印相关信息,类似keras

model.export('image_classifier.tflite', 'image_labels.txt')
#导出tflite模型,image_labels即对应的类别