{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "1l8bWGmIJuQa" }, "source": [ "##### Copyright 2019 The TensorFlow Authors.\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "cellView": "form", "execution": { "iopub.execute_input": "2022-12-15T02:03:05.524695Z", "iopub.status.busy": "2022-12-15T02:03:05.524085Z", "iopub.status.idle": "2022-12-15T02:03:05.528326Z", "shell.execute_reply": "2022-12-15T02:03:05.527720Z" }, "id": "CPSnXS88KFEo" }, "outputs": [], "source": [ "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", "# you may not use this file except in compliance with the License.\n", "# You may obtain a copy of the License at\n", "#\n", "# https://www.apache.org/licenses/LICENSE-2.0\n", "#\n", "# Unless required by applicable law or agreed to in writing, software\n", "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", "# See the License for the specific language governing permissions and\n", "# limitations under the License." ] }, { "cell_type": "markdown", "metadata": { "id": "89xNCIO5hiCj" }, "source": [ "# 분산 전략을 사용한 모델 저장 및 불러오기" ] }, { "cell_type": "markdown", "metadata": { "id": "9Ejs4QVxIdAm" }, "source": [ "
![]() | \n",
" ![]() | \n",
" ![]() | \n",
" ![]() | \n",
"
input_shape
키워드 인수를 전달하여 입력 형상을 설정하면 Keras [순차형](https://www.tensorflow.org/guide/keras/functional) 및 함수형 API에서 `ConcreteFunction`을 생성할 수도 있습니다.\n",
"\n",
"모델에 추적된 `ConcreteFunction`이 있는지 확인하려면 `Model.save_spec`이 `None`인지 확인하세요."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-15T02:03:53.476992Z",
"iopub.status.busy": "2022-12-15T02:03:53.476427Z",
"iopub.status.idle": "2022-12-15T02:03:53.480473Z",
"shell.execute_reply": "2022-12-15T02:03:53.479815Z"
},
"id": "xAXise4eR0YJ"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(my_model.save_spec() is None)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "G2G_FQrWJAO3"
},
"source": [
"`tf.keras.Model.fit`을 사용하여 모델을 훈련하고 `save_spec`이 정의되고 모델 저장이 작동하는지 확인합니다."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-15T02:03:53.484101Z",
"iopub.status.busy": "2022-12-15T02:03:53.483511Z",
"iopub.status.idle": "2022-12-15T02:03:54.372636Z",
"shell.execute_reply": "2022-12-15T02:03:54.371874Z"
},
"id": "cv5LTi0zDkKS"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 1/2\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\r",
"1/7 [===>..........................] - ETA: 3s - loss: 12.1411"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r",
"7/7 [==============================] - 1s 3ms/step - loss: 11.9682\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 2/2\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\r",
"1/7 [===>..........................] - ETA: 0s - loss: 11.6855"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r",
"7/7 [==============================] - 0s 2ms/step - loss: 11.5175\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"INFO:tensorflow:Unsupported signature for serialization: ((TensorSpec(shape=(5, 5), dtype=tf.float32, name='gradient'),