国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

Tensorflow訓(xùn)練模型越來(lái)越慢的2種解決方案

2020-02-15 21:20:46
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

1 解決方案

【方案一】

載入模型結(jié)構(gòu)放在全局,即tensorflow會(huì)話外層。

'''載入模型結(jié)構(gòu):最關(guān)鍵的一步'''saver = tf.train.Saver()'''建立會(huì)話'''with tf.Session() as sess: for i in range(STEPS): '''開(kāi)始訓(xùn)練''' _, loss_1, acc, summary = sess.run([train_op_1, train_loss, train_acc, summary_op], feed_dict=feed_dict) '''保存模型''' saver.save(sess, save_path="./model/path", i)

【方案二】

在方案一的基礎(chǔ)上,將模型結(jié)構(gòu)放在圖會(huì)話的外部。

'''預(yù)測(cè)值'''train_logits= network_model.inference(inputs, keep_prob)'''損失值'''train_loss = network_model.losses(train_logits)'''優(yōu)化'''train_op = network_model.train(train_loss, learning_rate)'''準(zhǔn)確率'''train_acc = network_model.evaluation(train_logits, labels)'''模型輸入'''feed_dict = {inputs: x_batch, labels: y_batch, keep_prob: 0.5}'''載入模型結(jié)構(gòu)'''saver = tf.train.Saver()'''建立會(huì)話'''with tf.Session() as sess: for i in range(STEPS): '''開(kāi)始訓(xùn)練''' _, loss_1, acc, summary = sess.run([train_op_1, train_loss, train_acc, summary_op], feed_dict=feed_dict) '''保存模型''' saver.save(sess, save_path="./model/path", i) 

2 時(shí)間測(cè)試

通過(guò)不同方法測(cè)試訓(xùn)練程序,得到不同的訓(xùn)練時(shí)間,每執(zhí)行一次訓(xùn)練都重新載入圖結(jié)構(gòu),會(huì)使每一步的訓(xùn)練時(shí)間逐次增加,如果訓(xùn)練步數(shù)越大,后面訓(xùn)練速度越來(lái)越慢,最終可導(dǎo)致圖爆炸,而終止訓(xùn)練。

【時(shí)間累加】

2019-05-15 10:55:29.009205: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMAstep: 0, time cost: 1.8800880908966064step: 1, time cost: 1.592250108718872step: 2, time cost: 1.553826093673706step: 3, time cost: 1.5687050819396973step: 4, time cost: 1.5777575969696045step: 5, time cost: 1.5908267498016357step: 6, time cost: 1.5989274978637695step: 7, time cost: 1.6078357696533203step: 8, time cost: 1.6087186336517334step: 9, time cost: 1.6123006343841553step: 10, time cost: 1.6320762634277344step: 11, time cost: 1.6317598819732666step: 12, time cost: 1.6570467948913574step: 13, time cost: 1.6584930419921875step: 14, time cost: 1.6765813827514648step: 15, time cost: 1.6751370429992676step: 16, time cost: 1.7304580211639404step: 17, time cost: 1.7583982944488525

【時(shí)間均衡】

2019-05-15 13:03:49.394354: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 7048 MB memory) -> physical GPU (device: 1, name: Tesla P4, pci bus id: 0000:00:0d.0, compute capability: 6.1)step: 0, time cost: 1.9781079292297363loss1:6.78, loss2:5.47, loss3:5.27, loss4:7.31, loss5:5.44, loss6:6.87, loss7: 6.84Total loss: 43.98, accuracy: 0.04, steps: 0, time cost: 1.9781079292297363step: 1, time cost: 0.09688425064086914step: 2, time cost: 0.09693264961242676step: 3, time cost: 0.09671926498413086step: 4, time cost: 0.09688210487365723step: 5, time cost: 0.09646058082580566step: 6, time cost: 0.09669041633605957step: 7, time cost: 0.09666872024536133step: 8, time cost: 0.09651994705200195step: 9, time cost: 0.09705543518066406step: 10, time cost: 0.09690332412719727            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 石渠县| 溧水县| 嵩明县| 沾化县| 三明市| 华蓥市| 周口市| 长子县| 胶南市| 昌都县| 宁城县| 丰城市| 开封县| 富源县| 鹰潭市| 侯马市| 广东省| 汝州市| 秦皇岛市| 双辽市| 越西县| 福建省| 迁安市| 南和县| 凤翔县| 安泽县| 诸城市| 林口县| 高青县| 青田县| 郎溪县| 方城县| 黄浦区| 湖州市| 三门县| 三门县| 宜黄县| 云霄县| 阳东县| 额济纳旗| 恭城|