{ "cells": [ { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "import tensorflow as tf\n", "weights = \"imagenet\"" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "def convert_keras_to_tfjs(model, filename):\n", " model.save(filename + \".h5\")\n", " import os\n", " os.mkdir(filename)\n", " os.system(\"tensorflowjs_converter --input_format keras ./{}.h5 ./{}\".format(filename, filename))\n", " os.system(\"rm {}.h5\".format(filename))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Densenet201" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/densenet/densenet201_weights_tf_dim_ordering_tf_kernels_notop.h5\n", "74836368/74836368 [==============================] - 5s 0us/step\n", "WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/teosanchez/anaconda3/lib/python3.11/site-packages/keras/src/engine/training.py:3079: UserWarning: You are saving your model as an HDF5 file via `model.save()`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')`.\n", " saving_api.save_model(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.\n" ] } ], "source": [ "pooling = [\"avg\", \"max\"]\n", "for pool in pooling:\n", " model = tf.keras.applications.DenseNet201(include_top = False, weights = weights, pooling = pool)\n", " filename = \"densenet201_pooling={1}\".format(weights, pool)\n", " convert_keras_to_tfjs(model, filename)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Densenet169" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.\n", "WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.\n" ] } ], "source": [ "pooling = [\"avg\", \"max\"]\n", "for pool in pooling:\n", " model = tf.keras.applications.DenseNet169(include_top = False, weights = weights, pooling = pool)\n", " filename = \"densenet169_pooling={1}\".format(weights, pool)\n", " convert_keras_to_tfjs(model, filename)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Resnet152" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/resnet/resnet152_weights_tf_dim_ordering_tf_kernels_notop.h5\n", "234698864/234698864 [==============================] - 10s 0us/step\n", "WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/teosanchez/anaconda3/lib/python3.11/site-packages/keras/src/engine/training.py:3079: UserWarning: You are saving your model as an HDF5 file via `model.save()`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')`.\n", " saving_api.save_model(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.\n" ] } ], "source": [ "pooling = [\"avg\", \"max\"]\n", "for pool in pooling:\n", " model = tf.keras.applications.ResNet152(include_top = False, weights = weights, pooling = pool)\n", " filename = \"resnet152_pooling={1}\".format(weights, pool)\n", " convert_keras_to_tfjs(model, filename)" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 2 }