File size: 5,445 Bytes
d8ffefa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | {
"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
}
|