<jupyter_start><jupyter_text>Convert model including preprocessing steps<jupyter_code>from keras_vggface import VGGFace
import tensorflow as tf
from keras_vggface.models import preprocessing<jupyter_output><empty_output><jupyter_text>Using old model<jupyter_code># model = VGGFace(model='senet50')
# img = image.load_img('image/ajb-resized.jpg', target_size=(224,224), interpolation="bilinear")
# x = image.img_to_array(img)
# x = np.expand_dims(x, axis=0)
# x = utils.preprocess_input(x, version=2)
# preds = model.predict(x)
# print('Predicted:', utils.decode_predictions(preds))
# # Output of normal:               [[["b' A._J._Buckley'", 0.91385096], ["b' Guy_Garvey'", 0.009176245], ["b' Jeff_Corwin'", 0.008781389], ["b' Michael_Voltaggio'", 0.0073467665], ["b' Nick_Frost'", 0.0065856054]]]
# # Output of custom preprocessing: [[["b' A._J._Buckley'", 0.91558367], ["b' Guy_Garvey'", 0.009039231], ["b' Jeff_Corwin'", 0.008346532], ["b' Michael_Voltaggio'", 0.0071733994], ["b' Nick_Frost'", 0.006603726]]]<jupyter_output><empty_output><jupyter_text>Helper function<jupyter_code>def create_tflite_model_file(model, filename):
    converter = tf.lite.TFLiteConverter.from_keras_model(model)
    tflite_model = converter.convert()
    with open(filename, 'wb') as f:
      f.write(tflite_model)<jupyter_output><empty_output><jupyter_text>First Model<jupyter_code>model = preprocessing()
create_tflite_model_file(model, 'preprocessing.tflite')<jupyter_output>WARNING:tensorflow:From /Users/ben/butter/repos/popsa/ds-face/venv/lib/python3.8/site-packages/tensorflow/python/training/tracking/tracking.py:111: Model.state_updates (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.
Instructions for updating:
This property should not be used in TensorFlow 2.0, as updates are applied automatically.
WARNING:tensorflow:From /Users/ben/butter/repos/popsa/ds-face/venv/lib/python3.8/site-packages/tensorflow/python/training/tracking/tracking.py:111: Layer.updates (from tensorflow.python.keras.engine.base_layer) is deprecated and will be removed in a future version.
Instructions for updating:
This property should not be used in TensorFlow 2.0, as updates are applied automatically.
INFO:tensorflow:Assets written to: /var/folders/rq/tslhk4cj60g2tlr0r5twqhf40000gq/T/tmpyv903xup/assets<jupyter_text>Second Model<jupyter_code>model = VGGFace(model="senet50", pooling="avg", include_top=False)
create_tflite_model_file(model, 'VggFace2SeNet.tflite')<jupyter_output>Using modified model
WARNING:tensorflow:From /Users/ben/butter/repos/popsa/ds-face/venv/lib/python3.8/site-packages/tensorflow/python/training/tracking/tracking.py:111: Model.state_updates (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.
Instructions for updating:
This property should not be used in TensorFlow 2.0, as updates are applied automatically.
WARNING:tensorflow:From /Users/ben/butter/repos/popsa/ds-face/venv/lib/python3.8/site-packages/tensorflow/python/training/tracking/tracking.py:111: Layer.updates (from tensorflow.python.keras.engine.base_layer) is deprecated and will be removed in a future version.
Instructions for updating:
This property should not be used in TensorFlow 2.0, as updates are applied automatically.
INFO:tensorflow:Assets written to: /var/folders/rq/tslhk4cj60g2tlr0r5twqhf40000gq/T/tmpljxeeit6/assets
{'fraction_non_alphanumeric': 0.12187958883994127, 'fraction_numerical': 0.04933920704845815, 'mean_word_length': 6.776255707762557, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '401965', 'license': 'MIT', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1186, 'n_words': 233, 'path': '.ipynb_checkpoints/Convert Model with Preprocessing-checkpoint.ipynb', 'repo_name': 'popsa-hq/keras-vggface', 'size': '3405'}