前言:
之前都是一次性训练好模型,但是一旦资料太多要训练,动辄就是数小时,甚至几天
所以我打算改善训练的过程,让它能储存上次进度来训练模组
程序码:
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
disable_eager_execution()
tf.compat.v1.experimental.output_all_intermediates(True)
checkpoint_path = "training_1/cp.ckpt"
checkpoint_dir = os.path.dirname(checkpoint_path)
# Create a callback that saves the model's weights
cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_path,
save_weights_only=True,
verbose=1)
# 输出整个网路结构
print(net_final.summary())
# 训练模型
net_final.fit(train_batches,
steps_per_epoch = train_batches.samples // BATCH_SIZE,
validation_data = valid_batches,
validation_steps = valid_batches.samples // BATCH_SIZE,
epochs = NUM_EPOCHS,
callbacks = [cp_callback])
os.listdir(checkpoint_dir)
因为JavaScript属於同步的语言,一次只能作一件事情,遇到非同步的事件就会把该事件挪到最後执行...
我们都说备份很重要,因此定时备份 Hexo 就是我们必学的其中一个功课之一啦!我们对 Hexo 的更...
Hoisting 先了解什麽是Hoisting,也就是宣告提升。 此种行为现象主因,是由於js在初始...
JUCE 不若 Qt 或其他知名开发框架,学习资源较多。相较之下,JUCE 的学习资源,寥寥可数。这...
在地狱厨房中,常常看到有人因为Risotto翻车导致戈登大吼骂人的画面,决定来挑战看看传统义大利炖...