def test_efficientnetb0_model(self):
     model = image_classifier.create(self.data,
                                     mef.ModelExportFormat.TFLITE,
                                     model_spec.efficientnet_b0_spec,
                                     epochs=5,
                                     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,
                                     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_mobilenetv2_model(self):
     model = image_classifier.create(self.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_topk(model)
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)

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

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

    model.export(FLAGS.tflite_filename, FLAGS.label_filename)
#
# Example taken from https://github.com/tensorflow/examples/blob/master/tensorflow_examples/lite/model_customization/demo/image_classification.ipynb
#
from __future__ import absolute_import, division, print_function, unicode_literals

import numpy as np

import tensorflow as tf
assert tf.__version__.startswith('2')

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

import matplotlib.pyplot as plt

#image_path = tf.keras.utils.get_file('dogs', 'images/dogs.tgz', untar=True)
data = ImageClassifierDataLoader.from_folder("images")
model = image_classifier.create(data)
loss, accuracy = model.evaluate()
model.export('dogs_classifier.tflite', 'dog_labels.txt')
 def test_mobilenetv2_model_create_v1_incompatible(self):
   with self.assertRaisesRegex(ValueError, 'Incompatible versions'):
     _ = image_classifier.create(self.train_data, mef.ModelExportFormat.TFLITE,
                                 model_spec.mobilenet_v2_spec)