IOS、Python自学心得30天 Day-14 H5与Pb模型档案

前言:
因为内存不足以在训练的时候存 SavedModel模型
所以我分离出来
以.h5档案先做训练
再以.h5档案载入
并用成.pb档案类型的储存方式
来达成目的

程序码:

import os
import tensorflow as tf
from tensorflow import keras
from tensorflow.python.keras import backend as K
from tensorflow.python.keras.models import Model
from tensorflow.python.keras.layers import Flatten, Dense, Dropout
from tensorflow.python.keras.applications.resnet import ResNet50
from tensorflow.python.keras.optimizer_v2.adam import Adam
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
from tensorflow.python.keras.models import Sequential, load_model
from tensorflow.python.keras.layers import LSTM, Dropout, Dense
from tensorflow.python.keras.callbacks import ModelCheckpoint
from tensorflow.python.framework.ops import disable_eager_execution


#解决内存配置不足的问题
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

# Allow memory growth for the GPU
physical_devices = tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)

disable_eager_execution()

tf.compat.v1.experimental.output_all_intermediates(True)

config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.compat.v1.Session(config=config)

net_final = load_model('model-resnet50-final.h5')
net_final.save('saved_model/my_model')

<<:  30天学会 Python: Day 1-印啦!哪次不印!

>>:  Day 17 self-attention的实作准备(三) 测试使用keras来建立模型

JS 25 - 举一反三,扩充专属於自己的函式库!

大家好! 今天要介绍的是最後一个静态方法。 我们进入今天的主题吧! 程序码 Felix.protot...

javascript基础功能2

现在要来学习如何制作一个表格,并且对其文字粗细加工,还有边框的变换以及表格的样式改变。 首先我们先打...

[Day 14]事件处理v-on

又是一个新的一天又要想今天要打什麽了(;´д`)ゞ,今天打算来讲v-on,以及讲解如何用v-on监听...

规划

大家好, 因为工作不太常用到AI/ML, 所以我自身会想要去多看多了解, 才不会脱钩 想当初整整研究...

Day 14 关键字品质分数

当你设置完关键字等广告,接着可以使用品质分数这个工具去观察,好让你可以适度做些调整,透过这些品质分数...