saved current state to various formats

This commit is contained in:
2023-02-01 01:30:11 +09:00
parent f11e895caf
commit 776eff1077
51 changed files with 1163 additions and 0 deletions

View File

@@ -603,6 +603,927 @@
"source": [
"tkinter.messagebox.showinfo(\"DONE\", \"DONE\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Save data for future use"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Keras weights file (<HDF5 file \"variables.h5\" (mode r+)>) saving:\n",
"...layers\n",
"......dense\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_1\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_2\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_3\n",
".........vars\n",
"............0\n",
"............1\n",
"......flatten\n",
".........vars\n",
"...metrics\n",
"......mean\n",
".........vars\n",
"............0\n",
"............1\n",
"......mean_metric_wrapper\n",
".........vars\n",
"............0\n",
"............1\n",
"...optimizer\n",
"......vars\n",
".........0\n",
".........1\n",
".........10\n",
".........11\n",
".........12\n",
".........13\n",
".........14\n",
".........15\n",
".........16\n",
".........2\n",
".........3\n",
".........4\n",
".........5\n",
".........6\n",
".........7\n",
".........8\n",
".........9\n",
"...vars\n",
"Keras model archive saving:\n",
"File Name Modified Size\n",
"variables.h5 2023-02-01 01:27:30 2497920\n",
"config.json 2023-02-01 01:27:30 2425\n",
"metadata.json 2023-02-01 01:27:30 64\n",
"Keras weights file (<HDF5 file \"variables.h5\" (mode r+)>) saving:\n",
"...layers\n",
"......dense\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_1\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_2\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_3\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_4\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_5\n",
".........vars\n",
"............0\n",
"............1\n",
"......flatten\n",
".........vars\n",
"...metrics\n",
"......mean\n",
".........vars\n",
"............0\n",
"............1\n",
"......mean_metric_wrapper\n",
".........vars\n",
"............0\n",
"............1\n",
"...optimizer\n",
"......vars\n",
".........0\n",
".........1\n",
".........10\n",
".........11\n",
".........12\n",
".........13\n",
".........14\n",
".........15\n",
".........16\n",
".........17\n",
".........18\n",
".........19\n",
".........2\n",
".........20\n",
".........21\n",
".........22\n",
".........23\n",
".........24\n",
".........3\n",
".........4\n",
".........5\n",
".........6\n",
".........7\n",
".........8\n",
".........9\n",
"...vars\n",
"Keras model archive saving:\n",
"File Name Modified Size\n",
"variables.h5 2023-02-01 01:27:30 2605296\n",
"config.json 2023-02-01 01:27:30 3278\n",
"metadata.json 2023-02-01 01:27:30 64\n",
"Keras weights file (<HDF5 file \"variables.h5\" (mode r+)>) saving:\n",
"...layers\n",
"......dense\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_1\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_10\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_2\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_3\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_4\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_5\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_6\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_7\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_8\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_9\n",
".........vars\n",
"............0\n",
"............1\n",
"......flatten\n",
".........vars\n",
"...metrics\n",
"......mean\n",
".........vars\n",
"............0\n",
"............1\n",
"......mean_metric_wrapper\n",
".........vars\n",
"............0\n",
"............1\n",
"...optimizer\n",
"......vars\n",
".........0\n",
".........1\n",
".........10\n",
".........11\n",
".........12\n",
".........13\n",
".........14\n",
".........15\n",
".........16\n",
".........17\n",
".........18\n",
".........19\n",
".........2\n",
".........20\n",
".........21\n",
".........22\n",
".........23\n",
".........24\n",
".........25\n",
".........26\n",
".........27\n",
".........28\n",
".........29\n",
".........3\n",
".........30\n",
".........31\n",
".........32\n",
".........33\n",
".........34\n",
".........35\n",
".........36\n",
".........37\n",
".........38\n",
".........39\n",
".........4\n",
".........40\n",
".........41\n",
".........42\n",
".........43\n",
".........44\n",
".........5\n",
".........6\n",
".........7\n",
".........8\n",
".........9\n",
"...vars\n",
"Keras model archive saving:\n",
"File Name Modified Size\n",
"variables.h5 2023-02-01 01:27:30 2876328\n",
"config.json 2023-02-01 01:27:30 5403\n",
"metadata.json 2023-02-01 01:27:30 64\n",
"Keras weights file (<HDF5 file \"variables.h5\" (mode r+)>) saving:\n",
"...layers\n",
"......conv2d\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_1\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_2\n",
".........vars\n",
"............0\n",
"............1\n",
"......flatten\n",
".........vars\n",
"......max_pooling2d\n",
".........vars\n",
"...metrics\n",
"......mean\n",
".........vars\n",
"............0\n",
"............1\n",
"......mean_metric_wrapper\n",
".........vars\n",
"............0\n",
"............1\n",
"...optimizer\n",
"......vars\n",
".........0\n",
".........1\n",
".........10\n",
".........11\n",
".........12\n",
".........13\n",
".........14\n",
".........15\n",
".........16\n",
".........2\n",
".........3\n",
".........4\n",
".........5\n",
".........6\n",
".........7\n",
".........8\n",
".........9\n",
"...vars\n",
"Keras model archive saving:\n",
"File Name Modified Size\n",
"variables.h5 2023-02-01 01:27:30 5630656\n",
"config.json 2023-02-01 01:27:30 2761\n",
"metadata.json 2023-02-01 01:27:30 64\n",
"Keras weights file (<HDF5 file \"variables.h5\" (mode r+)>) saving:\n",
"...layers\n",
"......conv2d\n",
".........vars\n",
"............0\n",
"............1\n",
"......conv2d_1\n",
".........vars\n",
"............0\n",
"............1\n",
"......conv2d_2\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_1\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_2\n",
".........vars\n",
"............0\n",
"............1\n",
"......flatten\n",
".........vars\n",
"......max_pooling2d\n",
".........vars\n",
"......max_pooling2d_1\n",
".........vars\n",
"......max_pooling2d_2\n",
".........vars\n",
"...metrics\n",
"......mean\n",
".........vars\n",
"............0\n",
"............1\n",
"......mean_metric_wrapper\n",
".........vars\n",
"............0\n",
"............1\n",
"...optimizer\n",
"......vars\n",
".........0\n",
".........1\n",
".........10\n",
".........11\n",
".........12\n",
".........13\n",
".........14\n",
".........15\n",
".........16\n",
".........17\n",
".........18\n",
".........19\n",
".........2\n",
".........20\n",
".........21\n",
".........22\n",
".........23\n",
".........24\n",
".........3\n",
".........4\n",
".........5\n",
".........6\n",
".........7\n",
".........8\n",
".........9\n",
"...vars\n",
"Keras model archive saving:\n",
"File Name Modified Size\n",
"variables.h5 2023-02-01 01:27:30 1615704\n",
"config.json 2023-02-01 01:27:30 4286\n",
"metadata.json 2023-02-01 01:27:30 64\n",
"Keras weights file (<HDF5 file \"variables.h5\" (mode r+)>) saving:\n",
"...layers\n",
"......dense\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_1\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_2\n",
".........vars\n",
"............0\n",
"............1\n",
"......flatten\n",
".........vars\n",
"......functional\n",
".........layers\n",
"............conv2d\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_1\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_10\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_11\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_12\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_2\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_3\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_4\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_5\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_6\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_7\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_8\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_9\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............input_layer\n",
"...............vars\n",
"............max_pooling2d\n",
"...............vars\n",
"............max_pooling2d_1\n",
"...............vars\n",
"............max_pooling2d_2\n",
"...............vars\n",
"............max_pooling2d_3\n",
"...............vars\n",
"............max_pooling2d_4\n",
"...............vars\n",
".........vars\n",
"...metrics\n",
"......mean\n",
".........vars\n",
"............0\n",
"............1\n",
"......mean_metric_wrapper\n",
".........vars\n",
"............0\n",
"............1\n",
"...optimizer\n",
"......vars\n",
".........0\n",
".........1\n",
".........10\n",
".........11\n",
".........12\n",
".........2\n",
".........3\n",
".........4\n",
".........5\n",
".........6\n",
".........7\n",
".........8\n",
".........9\n",
"...vars\n",
"Keras model archive saving:\n",
"File Name Modified Size\n",
"variables.h5 2023-02-01 01:27:31 59356288\n",
"config.json 2023-02-01 01:27:30 11981\n",
"metadata.json 2023-02-01 01:27:30 64\n",
"Keras weights file (<HDF5 file \"variables.h5\" (mode r+)>) saving:\n",
"...layers\n",
"......dense\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_1\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_2\n",
".........vars\n",
"............0\n",
"............1\n",
"......flatten\n",
".........vars\n",
"......functional\n",
".........layers\n",
"............conv2d\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_1\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_10\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_11\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_12\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_2\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_3\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_4\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_5\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_6\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_7\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_8\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_9\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............input_layer\n",
"...............vars\n",
"............max_pooling2d\n",
"...............vars\n",
"............max_pooling2d_1\n",
"...............vars\n",
"............max_pooling2d_2\n",
"...............vars\n",
"............max_pooling2d_3\n",
"...............vars\n",
"............max_pooling2d_4\n",
"...............vars\n",
".........vars\n",
"...metrics\n",
"......mean\n",
".........vars\n",
"............0\n",
"............1\n",
"......mean_metric_wrapper\n",
".........vars\n",
"............0\n",
"............1\n",
"...optimizer\n",
"......vars\n",
".........0\n",
".........1\n",
".........10\n",
".........11\n",
".........12\n",
".........13\n",
".........14\n",
".........15\n",
".........16\n",
".........17\n",
".........18\n",
".........19\n",
".........2\n",
".........20\n",
".........21\n",
".........22\n",
".........23\n",
".........24\n",
".........25\n",
".........26\n",
".........27\n",
".........28\n",
".........29\n",
".........3\n",
".........30\n",
".........31\n",
".........32\n",
".........33\n",
".........34\n",
".........35\n",
".........36\n",
".........37\n",
".........38\n",
".........39\n",
".........4\n",
".........40\n",
".........41\n",
".........42\n",
".........43\n",
".........44\n",
".........45\n",
".........46\n",
".........47\n",
".........48\n",
".........49\n",
".........5\n",
".........50\n",
".........51\n",
".........52\n",
".........53\n",
".........54\n",
".........55\n",
".........56\n",
".........57\n",
".........58\n",
".........59\n",
".........6\n",
".........60\n",
".........61\n",
".........62\n",
".........63\n",
".........64\n",
".........7\n",
".........8\n",
".........9\n",
"...vars\n",
"Keras model archive saving:\n",
"File Name Modified Size\n",
"variables.h5 2023-02-01 01:27:31 177093096\n",
"config.json 2023-02-01 01:27:31 12379\n",
"metadata.json 2023-02-01 01:27:31 64\n",
"Keras weights file (<HDF5 file \"variables.h5\" (mode r+)>) saving:\n",
"...layers\n",
"......dense\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_1\n",
".........vars\n",
"............0\n",
"............1\n",
"......dense_2\n",
".........vars\n",
"............0\n",
"............1\n",
"......flatten\n",
".........vars\n",
"......functional\n",
".........layers\n",
"............conv2d\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_1\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_10\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_11\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_12\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_2\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_3\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_4\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_5\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_6\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_7\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_8\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............conv2d_9\n",
"...............vars\n",
"..................0\n",
"..................1\n",
"............input_layer\n",
"...............vars\n",
"............max_pooling2d\n",
"...............vars\n",
"............max_pooling2d_1\n",
"...............vars\n",
"............max_pooling2d_2\n",
"...............vars\n",
"............max_pooling2d_3\n",
"...............vars\n",
"............max_pooling2d_4\n",
"...............vars\n",
".........vars\n",
"...metrics\n",
"......mean\n",
".........vars\n",
"............0\n",
"............1\n",
"......mean_metric_wrapper\n",
".........vars\n",
"............0\n",
"............1\n",
"...optimizer\n",
"......vars\n",
".........0\n",
".........1\n",
".........10\n",
".........11\n",
".........12\n",
".........2\n",
".........3\n",
".........4\n",
".........5\n",
".........6\n",
".........7\n",
".........8\n",
".........9\n",
"...vars\n",
"Keras model archive saving:\n",
"File Name Modified Size\n",
"variables.h5 2023-02-01 01:27:32 59356288\n",
"config.json 2023-02-01 01:27:31 12391\n",
"metadata.json 2023-02-01 01:27:31 64\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:absl:Found untraced functions such as _update_step_xla while saving (showing 1 of 1). These functions will not be directly callable after loading.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/regular Neural Network (3 hidden layers)/assets\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/regular Neural Network (3 hidden layers)/assets\n",
"WARNING:absl:Found untraced functions such as _update_step_xla while saving (showing 1 of 1). These functions will not be directly callable after loading.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/regular Neural Network (5 hidden layers)/assets\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/regular Neural Network (5 hidden layers)/assets\n",
"WARNING:absl:Found untraced functions such as _update_step_xla while saving (showing 1 of 1). These functions will not be directly callable after loading.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/regular Neural Network (10 hidden layers)/assets\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/regular Neural Network (10 hidden layers)/assets\n",
"WARNING:absl:Found untraced functions such as _jit_compiled_convolution_op, _update_step_xla while saving (showing 2 of 2). These functions will not be directly callable after loading.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/convolutional neural network (1 convolution)/assets\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/convolutional neural network (1 convolution)/assets\n",
"WARNING:absl:Found untraced functions such as _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _update_step_xla while saving (showing 4 of 4). These functions will not be directly callable after loading.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/convolutional neural network (3 convolutions)/assets\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/convolutional neural network (3 convolutions)/assets\n",
"WARNING:absl:Found untraced functions such as _update_step_xla, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op while saving (showing 5 of 14). These functions will not be directly callable after loading.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/frozen VGG16 base model/assets\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/frozen VGG16 base model/assets\n",
"WARNING:absl:Found untraced functions such as _update_step_xla, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op while saving (showing 5 of 14). These functions will not be directly callable after loading.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/fully trainable VGG16 base model/assets\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/fully trainable VGG16 base model/assets\n",
"WARNING:absl:Found untraced functions such as _update_step_xla, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op while saving (showing 5 of 14). These functions will not be directly callable after loading.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/partly trainable VGG16 base model/assets\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:tensorflow:Assets written to: saved_models/partly trainable VGG16 base model/assets\n"
]
}
],
"source": [
"# store histories with pickle\n",
"import pickle\n",
"histories = {}\n",
"for config_name, config in configs.items():\n",
" histories[config_name] = config['history']\n",
"with open('savepoint.pkl', 'wb') as out:\n",
" pickle.dump(histories, out)\n",
"\n",
"# store models with tensorflow\n",
"for config_name, config in configs.items():\n",
" config['model'].save(f'saved_models/{config_name}')\n",
"\n",
"# store models in HDF5 format\n",
"for config_name, config in configs.items():\n",
" config['model'].save(f'hdf5_models/{config_name}.h5')\n"
]
}
],
"metadata": {

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

BIN
savepoint.pkl Normal file

Binary file not shown.

14
test.py Normal file
View File

@@ -0,0 +1,14 @@
import tensorflow as tf
import tensorflow_datasets as tfds
new_model = tf.keras.models.load_model('hdf5_models/fully trainable VGG16 base model.h5')
new_model.summary()
ds_train, ds_test = tfds.load(
'svhn_cropped',
split=['train', 'test'],
shuffle_files=True,
as_supervised=True
)
loss, acc = new_model.evaluate(ds_test, verbose=2)
print('Restored model, accuracy: {:5.2f}%'.format(100 * acc))