python神經(jīng)網(wǎng)絡(luò)slim常用函數(shù)訓(xùn)練保存模型
學(xué)習(xí)前言
在SSD的框架中,除去tfrecord處理是非常重要的一環(huán)之外,slim框架的使用也是非常重要的一環(huán),于是我開始學(xué)習(xí)slim啦
slim是什么
slim的英文本意是苗條的意思,其實(shí)在tensorflow中,它相當(dāng)于就是tensorflow簡潔版的意思,直接使用tensorflow構(gòu)建代碼可能會(huì)比較復(fù)雜,使用slim可以將一些tensorflow代碼合并在一起,其具體作用與keras類似。
但是相比Keras,slim更加貼近tensorflow原生,其更加輕量級。
TF-Slim是tensorflow中定義、訓(xùn)練和評估復(fù)雜模型的輕量級庫。tf-slim中的組件可以輕易地和原生tensorflow框架以及例如tf.contrib.learn這樣的框架進(jìn)行整合。
slim常用函數(shù)
1、slim = tf.contrib.slim
slim = tf.contrib.slim用于在python中聲明slim框架的對象,只有完成該聲明后才可以利用slim框架構(gòu)建tensorflow神經(jīng)網(wǎng)絡(luò)。
2、slim.create_global_step
該函數(shù)用于生成全局步數(shù),全局步數(shù)可以用于學(xué)習(xí)率的自適應(yīng)衰減。
3、slim.dataset.Dataset
該函數(shù)用于從tfrecords類型的文件中獲取數(shù)據(jù),實(shí)際上是利用該數(shù)據(jù)生成了一個(gè)數(shù)據(jù)庫,在slim之后訓(xùn)練時(shí)可以從中獲取數(shù)據(jù)用于訓(xùn)練。常見的Dataset使用方式如下:
slim.dataset.Dataset(
data_sources=record_path,
reader=reader,
decoder=decoder,
num_samples=num_samples,
num_classes=num_classes,
items_to_descriptions=items_to_descriptions,
labels_to_names=labels_to_names)
其中:
- file_pattern指向tfrecords文件的位置;
- reader默認(rèn)是tf.TFRecordReader,也就是tensorflow支持的tfrecord讀取器;
- decoder指的是如何將tfrecord文件里的內(nèi)容解碼成自己需要的內(nèi)容;
- num_samples指的是tfrecord文件里一共具有多少個(gè)樣本;
- items_to_descriptions是解碼后每個(gè)項(xiàng)目的描述;
- num_classes是值一共有多少個(gè)種類
其內(nèi)部參數(shù)具體的設(shè)置方式如下,本段代碼主要是對神經(jīng)網(wǎng)絡(luò)學(xué)習(xí)tfrecords文件的寫入、讀取及其內(nèi)容解析中MNIST數(shù)據(jù)集進(jìn)行slim數(shù)據(jù)庫的構(gòu)建,如果不知道如何構(gòu)建tfrecord文件的可以看我的上一篇博文。
def get_record_dataset(record_path,
reader=None, image_shape=[784],
num_samples=55000, num_classes=10):
if not reader:
reader = tf.TFRecordReader
keys_to_features = {
'image/encoded': tf.FixedLenFeature([784], tf.float32, default_value=tf.zeros([784], dtype=tf.float32)),
'image/class/label':tf.FixedLenFeature([1], tf.int64,
default_value=tf.zeros([1], dtype=tf.int64))}
items_to_handlers = {
'image': slim.tfexample_decoder.Tensor('image/encoded', shape = [784]),
'label': slim.tfexample_decoder.Tensor('image/class/label', shape=[])}
decoder = slim.tfexample_decoder.TFExampleDecoder(
keys_to_features, items_to_handlers)
labels_to_names = None
items_to_descriptions = {
'image': 'An image with shape image_shape.',
'label': 'A single integer between 0 and 9.'}
return slim.dataset.Dataset(
data_sources=record_path,
reader=reader,
decoder=decoder,
num_samples=num_samples,
num_classes=num_classes,
items_to_descriptions=items_to_descriptions,
labels_to_names=labels_to_names)
本段代碼分別對image和label進(jìn)行讀取。
其中:
- items_to_handlers指的是數(shù)據(jù)在tfrecords中的存儲(chǔ)方式;
- items_to_handlers指的是數(shù)據(jù)解碼后的格式;
- decoder用于將items_to_handlers與items_to_handlers結(jié)合使用;
- items_to_descriptions是解碼后每個(gè)數(shù)據(jù)的描述。
4、slim.dataset_data_provider.DatasetDataProvider
上一步的函數(shù)構(gòu)成的是數(shù)據(jù)庫,但是如何從數(shù)據(jù)庫里面讀取數(shù)據(jù)我們還不知道,實(shí)際上slim已經(jīng)給了一個(gè)函數(shù)作為數(shù)據(jù)庫的接口,利用該函數(shù)可以生成provider,顧名思義,provider就是數(shù)據(jù)庫向外界提供數(shù)據(jù)的接口。
具體使用方式如下:
# 創(chuàng)建provider
provider = slim.dataset_data_provider.DatasetDataProvider(
dataset,
num_readers= FLAGS.num_readers,
common_queue_capacity=20*FLAGS.batch_size,
common_queue_min=10*FLAGS.batch_size,
shuffle=True)
# 在提供商處獲取image
image, label = provider.get(['image', 'label'])
其中:
- dataset就是數(shù)據(jù)庫;
- num_readers指的是使用的并行讀取器的數(shù)量;
- common_queue_capacity指的是公共隊(duì)列的容量;
- common_queue_min指的是公共隊(duì)列出隊(duì)后的最小元素個(gè)數(shù);
- shuffle指的是讀取時(shí)是否打亂順序。
在提供商處獲取image后,可以利用tf.train.batch分批次獲取訓(xùn)練集。
inputs, labels = tf.train.batch([image, label],
batch_size=FLAGS.batch_size,
allow_smaller_final_batch=True,
num_threads=FLAGS.num_readers,
capacity=FLAGS.batch_size*5)
其中:
- batch_size指的是每一個(gè)批次訓(xùn)練集的數(shù)量;
- allow_smaller_final_batch指的是是否允許存在batch小于batch_size的數(shù)據(jù)集;
- num_threads指的是用的線程數(shù);
- capacity一個(gè)整數(shù),用來設(shè)置隊(duì)列中元素的最大數(shù)量。
tf.train.batch具體的使用方法可以參照我的另一篇博文神經(jīng)網(wǎng)絡(luò)之批量學(xué)習(xí)tf.train.batch
此時(shí)獲得的inputs, labels可以在下一步傳入網(wǎng)絡(luò)了。
5、slim.conv2d
slim.conv2d用于構(gòu)建卷積層,其具體的代碼如下:
slim.conv2d(inputs,
num_outputs,
kernel_size,
stride=1,
padding='SAME',
data_format=None,
rate=1,
activation_fn=nn.relu,
normalizer_fn=None,
normalizer_params=None,
weights_initializer=initializers.xavier_initializer(),
weights_regularizer=None,
biases_initializer=init_ops.zeros_initializer(),
biases_regularizer=None,
reuse=None,
variables_collections=None,
outputs_collections=None,
trainable=True,
scope=None)
其中參數(shù)很多,常用的參數(shù)解析如下:
- inputs指的是需要做卷積的輸入圖像;
- num_outputs指的是卷積核的個(gè)數(shù),也就輸出net的channels數(shù)量;
- kernel_size指的是卷積核的維度,用一個(gè)列表或元組表示;
- stride指的是卷積時(shí)在圖像每一維的步長;
- padding使用VALID或者SAME;
- data_format指的是輸入的input的格式,NCHW 與 NHWC;
- rate指的是使用空洞卷積的膨脹率;
- activation_fn指的是激活函數(shù)的種類,默認(rèn)的為ReLU函數(shù);
- normalizer_fn指的是正則化函數(shù);
- reuse指的是是否共享層或者和變量;
- trainable指的是卷積層的參數(shù)是否可被訓(xùn)練;
- scope指的是共享變量所指的variable_scope。
6、slim.max_pool2d
slim.max_pool2d用于最大池化,具體代碼如下:
slim.fully_connected(inputs,
num_outputs,
activation_fn=nn.relu,
normalizer_fn=None,
normalizer_params=None,
weights_initializer=initializers.xavier_initializer(),
weights_regularizer=None,
biases_initializer=init_ops.zeros_initializer(),
biases_regularizer=None,
reuse=None,
variables_collections=None,
outputs_collections=None,
trainable=True,
scope=None)
其中:
- inputs指的是指需要做卷積的輸入圖像;
- kernel_size指的是池化核的維度,用一個(gè)列表或元組表示;
- stride指的是池化的步長;
- padding使用VALID或者SAME;
- data_format支持’ NHWC ‘(默認(rèn)值)和’ NCHW ';
- scope指的是name_scope的可選作用域。
7、slim.fully_connected
slim.fully_connected用于定義全連接層。
具體代碼如下:
slim.fully_connected(inputs,
num_outputs,
activation_fn=nn.relu,
normalizer_fn=None,
normalizer_params=None,
weights_initializer=initializers.xavier_initializer(),
weights_regularizer=None,
biases_initializer=init_ops.zeros_initializer(),
biases_regularizer=None,
reuse=None,
variables_collections=None,
outputs_collections=None,
trainable=True,
scope=None)
其中:
- inputs指的是指需要全連接的數(shù)據(jù);
- num_outputs指的是輸出的維度;
- activation_fn指的是激活函數(shù);
- weights_initializer指的是權(quán)值初始化方法;
- biases_initializer指的是閾值初始化方法;
- trainable指的是是否可以訓(xùn)練;
- scope指的是name_scope的可選作用域。
8、slim.learning.train
該函數(shù)用于將訓(xùn)練托管給slim框架進(jìn)行,非常好用,具體使用代碼如下。
slim.learning.train(
train_op,
logdir=FLAGS.train_dir,
master='',
is_chief=True,
number_of_steps = FLAGS.max_number_of_steps,
log_every_n_steps = FLAGS.log_every_n_steps,
save_summaries_secs= FLAGS.save_summaries_secs,
saver=saver,
save_interval_secs = FLAGS.save_interval_secs,
session_config=config,
sync_optimizer=None)
其中:
- train_op為訓(xùn)練對象,可以利用slim.learning.create_train_op構(gòu)建;
- logdir為模型訓(xùn)練產(chǎn)生日志的地址;
- master指的是tensorflow master的地址;
- is_chief指的是是否在主要副本上運(yùn)行training;
- number_of_steps指的是訓(xùn)練時(shí)最大的梯度更新次數(shù),當(dāng)global step大于這個(gè)值時(shí),停止訓(xùn)練。如果這個(gè)值為None,則訓(xùn)練不會(huì)停止下來;
- log_every_n_steps指的是多少步在cmd上進(jìn)行顯示;
- save_summaries_secs指的是多久進(jìn)行一次數(shù)據(jù)的summaries;
- saver指的是保存模型的方法;
- save_interval_secs指的是多久保存一次模型;
- session_config指的是tf.ConfigProto的一個(gè)實(shí)例,用于配置Session;
- sync_optimizer指的是tf.train.SyncReplicasOptimizer的一個(gè)實(shí)例,或者這個(gè)實(shí)例的一個(gè)列表。如果這個(gè)參數(shù)被更新,則梯度更新操作將同步進(jìn)行。如果為None,則梯度更新操作將異步進(jìn)行。
其使用的參數(shù)較多,具體配置方式如下,并不復(fù)雜:
# 獲得損失值
loss = Conv_Net.get_loss(labels=labels,logits = logits)
# 學(xué)習(xí)率多久衰減一次
decay_steps = int(dataset.num_samples / FLAGS.batch_size *
FLAGS.num_epochs_per_decay)
# 學(xué)習(xí)率指數(shù)下降
learning_rate = tf.train.exponential_decay(FLAGS.learning_rate,
global_step,
decay_steps,
FLAGS.learning_rate_decay_factor,
staircase=False,
name='exponential_decay_learning_rate')
# 優(yōu)化器
optimizer = tf.train.AdamOptimizer(learning_rate)
# 構(gòu)建訓(xùn)練對象
train_op = slim.learning.create_train_op(loss, optimizer,
summarize_gradients=False)
# gpu使用比率
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=FLAGS.gpu_memory_fraction,
allow_growth = True)
# 參數(shù)配置
config = tf.ConfigProto(allow_soft_placement=True,
log_device_placement=False,
gpu_options=gpu_options)
# 保存方式
saver = tf.train.Saver(max_to_keep=5,
keep_checkpoint_every_n_hours=1.0,
write_version=2,
pad_step_number=False)
本次博文實(shí)現(xiàn)的目標(biāo)
本次博文主要是利用slim構(gòu)建了一個(gè)卷積神經(jīng)網(wǎng)絡(luò),用于手寫體的識(shí)別,經(jīng)過20000次訓(xùn)練后,精度達(dá)到99.2%。
已經(jīng)存儲(chǔ)好的tfrecords也可以點(diǎn)擊下載
整體框架構(gòu)建思路
1、整體框架
整個(gè)思路的構(gòu)建如下圖所示:

其中:
- Net.py是網(wǎng)絡(luò)的主體;
- CNN.py進(jìn)行模型訓(xùn)練的主體;
- Load_Predict.py是如何用模型進(jìn)行預(yù)測(下一個(gè)博文講解);
- TFrecord_read和TF_record_write主要是用于tfrecord文件的生成。
2、網(wǎng)絡(luò)構(gòu)建Net.py
網(wǎng)絡(luò)構(gòu)建部分的函數(shù)比較簡單,主要是設(shè)計(jì)了一個(gè)對象用于讀取網(wǎng)絡(luò)結(jié)構(gòu),網(wǎng)絡(luò)結(jié)構(gòu)比較簡單,其shape變化如下:
(28,28,1)=>(28,28,32)=>(14,14,32)=>(14,14,64)=>(7,7,64)=>(3136)=>(1024)=>(10)
import tensorflow as tf
import numpy as np
# 創(chuàng)建slim對象
slim = tf.contrib.slim
class Conv_Net(object):
def net(self,inputs):
with tf.variable_scope("Net"):
# 第一個(gè)卷積層
net = slim.conv2d(inputs,32,[5,5],padding = "SAME",scope = 'conv1_1')
net = slim.max_pool2d(net,[2,2],stride = 2,padding = "SAME",scope = 'pool1')
# 第二個(gè)卷積層
net = slim.conv2d(net,64,[3,3],padding = "SAME",scope = 'conv2_1')
net = slim.max_pool2d(net,[2,2],stride = 2,padding = "SAME",scope = 'pool2')
net = tf.reshape(net,[-1,7*7*64])
# 全連接層
layer1 = slim.fully_connected(net,512,scope = 'fully1')
layer1 = slim.dropout(layer1, 0.5, scope='dropout1')
# 這里的layer3忘了改成layer2了,試了很多結(jié)構(gòu),這個(gè)比較好
layer3 = slim.fully_connected(layer1,10,activation_fn=tf.nn.softmax,scope = 'fully3')
return layer3
def get_loss(self,labels,logits):
with tf.variable_scope("loss"):
loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(labels=labels,logits = logits),name = 'loss')
tf.summary.scalar("loss",loss)
return loss
3、進(jìn)行模型訓(xùn)練CNN.py
進(jìn)行模型訓(xùn)練CNN.py中的訓(xùn)練過程主要是模仿SSD的訓(xùn)練過程的框架構(gòu)成的,如果大家對SSD有疑問,歡迎大家看我的博文SSD算法訓(xùn)練部分詳解。
其具體的訓(xùn)練如下:
1、設(shè)定訓(xùn)練參數(shù)。
2、讀取MNIST數(shù)據(jù)集。
3、建立卷積神經(jīng)網(wǎng)絡(luò)。
4、將數(shù)據(jù)集的image通過神經(jīng)網(wǎng)絡(luò),獲得prediction。
5、利用prediction和實(shí)際label獲得loss。
6、利用優(yōu)化器完成梯度下降并保存模型。
具體代碼如下,其中所有執(zhí)行步驟已經(jīng)利用如下格式隔開:
############################################################# # XXXXXXXXXXXXX #############################################################
import tensorflow as tf
import numpy as np
from nets import Net
flags = tf.app.flags
#############################################################
# 設(shè)置訓(xùn)練參數(shù)
#############################################################
# =========================================================================== #
# General Flags.
# =========================================================================== #
# train_dir用于保存訓(xùn)練后的模型和日志
tf.app.flags.DEFINE_string(
'train_dir', './logs',
'Directory where checkpoints and event logs are written to.')
# num_readers是在對數(shù)據(jù)集進(jìn)行讀取時(shí)所用的平行讀取器個(gè)數(shù)
tf.app.flags.DEFINE_integer(
'num_readers', 4,
'The number of parallel readers that read data from the dataset.')
# 在進(jìn)行訓(xùn)練batch的構(gòu)建時(shí),所用的線程數(shù)
tf.app.flags.DEFINE_integer(
'num_preprocessing_threads', 4,
'The number of threads used to create the batches.')
# 每十步進(jìn)行一次log輸出,在窗口上
tf.app.flags.DEFINE_integer(
'log_every_n_steps', 100,
'The frequency with which logs are print.')
# 每150秒存儲(chǔ)一次記錄
tf.app.flags.DEFINE_integer(
'save_summaries_secs', 150,
'The frequency with which summaries are saved, in seconds.')
# 每150秒存儲(chǔ)一次模型
tf.app.flags.DEFINE_integer(
'save_interval_secs', 150,
'The frequency with which the model is saved, in seconds.')
# 可以使用的gpu內(nèi)存數(shù)量
tf.app.flags.DEFINE_float(
'gpu_memory_fraction', 0.6, 'GPU memory fraction to use.')
# =========================================================================== #
# Learning Rate Flags.
# =========================================================================== #
# 學(xué)習(xí)率衰減的方式,有固定、指數(shù)衰減等
tf.app.flags.DEFINE_string(
'learning_rate_decay_type',
'exponential',
'Specifies how the learning rate is decayed. One of "fixed", "exponential",'
' or "polynomial"')
# 初始學(xué)習(xí)率
tf.app.flags.DEFINE_float('learning_rate', 0.001, 'Initial learning rate.')
# 結(jié)束時(shí)的學(xué)習(xí)率
tf.app.flags.DEFINE_float(
'end_learning_rate', 0.0001,
'The minimal end learning rate used by a polynomial decay learning rate.')
tf.app.flags.DEFINE_float(
'label_smoothing', 0.0, 'The amount of label smoothing.')
# 學(xué)習(xí)率衰減因素
tf.app.flags.DEFINE_float(
'learning_rate_decay_factor', 0.94, 'Learning rate decay factor.')
tf.app.flags.DEFINE_float(
'num_epochs_per_decay', 2.0,
'Number of epochs after which learning rate decays.')
tf.app.flags.DEFINE_float(
'moving_average_decay', None,
'The decay to use for the moving average.'
'If left as None, then moving averages are not used.')
# adam參數(shù)
tf.app.flags.DEFINE_float(
'adam_beta1', 0.9,
'The exponential decay rate for the 1st moment estimates.')
tf.app.flags.DEFINE_float(
'adam_beta2', 0.999,
'The exponential decay rate for the 2nd moment estimates.')
tf.app.flags.DEFINE_float('opt_epsilon', 1.0, 'Epsilon term for the optimizer.')
# =========================================================================== #
# Dataset Flags.
# =========================================================================== #
# 數(shù)據(jù)集目錄
tf.app.flags.DEFINE_string(
'dataset_dir', './record/output.tfrecords', 'The directory where the dataset files are stored.')
# 每一次訓(xùn)練batch的大小
tf.app.flags.DEFINE_integer(
'batch_size', 100, 'The number of samples in each batch.')
# 最大訓(xùn)練次數(shù)
tf.app.flags.DEFINE_integer('max_number_of_steps', 20000,
'The maximum number of training steps.')
FLAGS = flags.FLAGS
def get_record_dataset(record_path,
reader=None, image_shape=[784],
num_samples=55000, num_classes=10):
if not reader:
reader = tf.TFRecordReader
keys_to_features = {
'image/encoded': tf.FixedLenFeature([784], tf.float32, default_value=tf.zeros([784], dtype=tf.float32)),
'image/class/label':tf.FixedLenFeature([1], tf.int64,
default_value=tf.zeros([1], dtype=tf.int64))}
items_to_handlers = {
'image': slim.tfexample_decoder.Tensor('image/encoded', shape = [784]),
'label': slim.tfexample_decoder.Tensor('image/class/label', shape=[])}
decoder = slim.tfexample_decoder.TFExampleDecoder(
keys_to_features, items_to_handlers)
labels_to_names = None
items_to_descriptions = {
'image': 'An image with shape image_shape.',
'label': 'A single integer between 0 and 9.'}
return slim.dataset.Dataset(
data_sources=record_path,
reader=reader,
decoder=decoder,
num_samples=num_samples,
num_classes=num_classes,
items_to_descriptions=items_to_descriptions,
labels_to_names=labels_to_names)
if __name__ == "__main__":
# 打印日志
tf.logging.set_verbosity(tf.logging.DEBUG)
with tf.Graph().as_default():
# 最大世代
MAX_EPOCH = 50000
# 創(chuàng)建slim對象
slim = tf.contrib.slim
# 步數(shù)
global_step = slim.create_global_step()
#############################################################
# 讀取MNIST數(shù)據(jù)集
#############################################################
# 讀取數(shù)據(jù)集
dataset = get_record_dataset(FLAGS.dataset_dir,num_samples = 55000)
# 創(chuàng)建provider
provider = slim.dataset_data_provider.DatasetDataProvider(
dataset,
num_readers= FLAGS.num_readers,
common_queue_capacity=20*FLAGS.batch_size,
common_queue_min=10*FLAGS.batch_size,
shuffle=True)
# 在提供商處獲取image
image, label = provider.get(['image', 'label'])
# 每次提取100個(gè)手寫體
inputs, labels = tf.train.batch([image, label],
batch_size=FLAGS.batch_size,
allow_smaller_final_batch=True,
num_threads=FLAGS.num_readers,
capacity=FLAGS.batch_size*5)
#############################################################
#建立卷積神經(jīng)網(wǎng)絡(luò),并將數(shù)據(jù)集的image通過神經(jīng)網(wǎng)絡(luò),獲得prediction。
#############################################################
inputs = tf.cast(inputs,tf.float32)
inputs_reshape = tf.reshape(inputs,[-1,28,28,1])
Conv_Net = Net.Conv_Net()
logits = Conv_Net.net(inputs_reshape)
#############################################################
# 利用prediction和實(shí)際label獲得loss。
#############################################################
# 獲得損失值
loss = Conv_Net.get_loss(labels = labels,logits = logits)
decay_steps = int(dataset.num_samples / FLAGS.batch_size *
FLAGS.num_epochs_per_decay)
# 學(xué)習(xí)率指數(shù)下降
learning_rate = tf.train.exponential_decay(FLAGS.learning_rate,
global_step,
decay_steps,
FLAGS.learning_rate_decay_factor,
staircase=False,
name='exponential_decay_learning_rate')
#############################################################
# 利用優(yōu)化器完成梯度下降并保存模型。
#############################################################
# 優(yōu)化器
optimizer = tf.train.AdamOptimizer(learning_rate)
# 構(gòu)建訓(xùn)練對象
train_op = slim.learning.create_train_op(loss, optimizer,
summarize_gradients=False)
# gpu使用比率
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=FLAGS.gpu_memory_fraction,
allow_growth = True)
# 參數(shù)配置
config = tf.ConfigProto(allow_soft_placement=True,
log_device_placement=False,
gpu_options=gpu_options)
# 保存方式
saver = tf.train.Saver(max_to_keep=5,
keep_checkpoint_every_n_hours=1.0,
write_version=2,
pad_step_number=False)
# 托管訓(xùn)練
slim.learning.train(
train_op,
logdir=FLAGS.train_dir,
master='',
is_chief=True,
number_of_steps = FLAGS.max_number_of_steps,
log_every_n_steps = FLAGS.log_every_n_steps,
save_summaries_secs= FLAGS.save_summaries_secs,
saver=saver,
save_interval_secs = FLAGS.save_interval_secs,
session_config=config,
sync_optimizer=None)
4、訓(xùn)練結(jié)果
在完成數(shù)據(jù)集的構(gòu)建后,直接運(yùn)行CNN.py就可以開始訓(xùn)練。訓(xùn)練的graph如下:

Net的內(nèi)容為(這里的layer3忘了改成layer2了,試了很多結(jié)構(gòu),這個(gè)比較好):

輸出的logs為:
…… INFO:tensorflow:global step 17899: loss = 1.4701 (0.040 sec/step) INFO:tensorflow:global step 17999: loss = 1.4612 (0.040 sec/step) INFO:tensorflow:global step 18099: loss = 1.4612 (0.051 sec/step) INFO:tensorflow:global step 18199: loss = 1.4612 (0.040 sec/step) INFO:tensorflow:global step 18299: loss = 1.4668 (0.048 sec/step) INFO:tensorflow:global step 18399: loss = 1.4615 (0.039 sec/step) INFO:tensorflow:global step 18499: loss = 1.4612 (0.050 sec/step) INFO:tensorflow:global step 18599: loss = 1.4812 (0.050 sec/step) INFO:tensorflow:global step 18699: loss = 1.4612 (0.060 sec/step) INFO:tensorflow:global step 18799: loss = 1.4712 (0.050 sec/step) INFO:tensorflow:global step 18899: loss = 1.4712 (0.040 sec/step) INFO:tensorflow:global step 18999: loss = 1.4716 (0.040 sec/step) INFO:tensorflow:global step 19199: loss = 1.4613 (0.040 sec/step) INFO:tensorflow:global step 19299: loss = 1.4619 (0.040 sec/step) INFO:tensorflow:global step 19399: loss = 1.4732 (0.040 sec/step) INFO:tensorflow:global step 19499: loss = 1.4612 (0.050 sec/step) INFO:tensorflow:global step 19599: loss = 1.4614 (0.040 sec/step) INFO:tensorflow:global step 19699: loss = 1.4612 (0.040 sec/step) INFO:tensorflow:global step 19799: loss = 1.4612 (0.040 sec/step) INFO:tensorflow:global step 19899: loss = 1.4612 (0.040 sec/step) INFO:tensorflow:global step 19999: loss = 1.4612 (0.040 sec/step) INFO:tensorflow:Stopping Training. INFO:tensorflow:Finished training! Saving model to disk.
以上就是python神經(jīng)網(wǎng)絡(luò)使用slim函數(shù)訓(xùn)練保存模型的詳細(xì)內(nèi)容,更多關(guān)于slim函數(shù)訓(xùn)練保存模型的資料請關(guān)注腳本之家其它相關(guān)文章!
- PyCharm提示No Python Interpreter的正確解決辦法
- pycharm遠(yuǎn)程連接服務(wù)器并配置python interpreter的方法
- python深度學(xué)習(xí)tensorflow訓(xùn)練好的模型進(jìn)行圖像分類
- Python實(shí)現(xiàn)自動(dòng)駕駛訓(xùn)練模型
- python神經(jīng)網(wǎng)絡(luò)AlexNet分類模型訓(xùn)練貓狗數(shù)據(jù)集
- python神經(jīng)網(wǎng)絡(luò)tensorflow利用訓(xùn)練好的模型進(jìn)行預(yù)測
- Python 實(shí)現(xiàn)LeNet網(wǎng)絡(luò)模型的訓(xùn)練及預(yù)測
- Python人工智能深度學(xué)習(xí)模型訓(xùn)練經(jīng)驗(yàn)總結(jié)
- python interpret庫訓(xùn)練模型助力機(jī)器學(xué)習(xí)
相關(guān)文章
Python requests接口測試實(shí)現(xiàn)代碼
這篇文章主要介紹了Python requests接口測試實(shí)現(xiàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09
Python安裝xarray庫讀取.nc文件的詳細(xì)步驟
大家應(yīng)該都知道庫xarray可以幫我們讀取出nc文件的內(nèi)容,所以下面這篇文章主要給大家介紹了關(guān)于Python安裝xarray讀取.nc文件的詳細(xì)步驟,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07
Python 文本滾動(dòng)播放器的實(shí)現(xiàn)代碼
這篇文章主要介紹了Python 文本滾動(dòng)播放器的實(shí)現(xiàn)代碼,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04
Python操作PostgreSql數(shù)據(jù)庫的方法(基本的增刪改查)
這篇文章主要介紹了Python操作PostgreSql數(shù)據(jù)庫(基本的增刪改查),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12
PyQt5實(shí)現(xiàn)進(jìn)度條與定時(shí)器及子線程同步關(guān)聯(lián)
這篇文章主要為大家詳細(xì)介紹了PyQt5如何實(shí)現(xiàn)進(jìn)度條與定時(shí)器及子線程的同步關(guān)聯(lián),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-01-01
Python中判斷subprocess調(diào)起的shell命令是否結(jié)束
這篇文章主要介紹了Python中判斷subprocess調(diào)起的shell命令是否結(jié)束的方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04
python環(huán)境下OPenCV處理視頻流局部區(qū)域像素值
這篇文章主要為大家介紹了python環(huán)境下OPenCV處理視頻流局部區(qū)域像素值的實(shí)現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2021-11-11

