91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

通過模塊化的編程思想,運用Tensorflow搭建的全連接神經網絡,代碼包括5個文件,分別為generateds.py;forward.py;backward.py;test.py;appMnist.py,分別對應生成數據集,前向傳播,反向傳播,測試模型,運用模型做預測的功能

資源截圖

代碼片段和文件信息

import?tensorflow?as?tf
import?numpy?as?np
import?forward
import?backward
from?PIL?import?Image

def?restore_model(testpicArr):
????#創建一個默認圖,在該圖中執行以下操作(多數操作和train中一樣)
????with?tf.Graph().as_default()?as?tg:
????????x?=?tf.placeholder(tf.float32[Noneforward.INPUT_NODE])
????????y?=?forward.forward((xNone))
????????preValue?=?tf.argmax(y1)?#得到概率最大的預測值

????????variable_averages?=?tf.train.ExponentialMovingAverage(backward.MOVING_AVERAGE_DECAY)
????????variables_to_restore?=?variable_averages.variables_to_restore()
????????saver?=?tf.train.Saver(variables_to_restore)

????????with?tf.Session()?as?sess:
????????????#通過chechpoint文件定位到罪行保存的模型
????????????ckpt?=?tf.train.get_checkpoint_state(backward.MODEL_SAVE_PATH)
????????????if?ckpt?and?ckpt.model_checkpoint_path:
????????????????saver.restore(sessckpt.model_checkpoint_path)
????????????????preValue?=?sess.run(preValuefeed_dict={x:testpicArr})
????????????????return?preValue
????????????else:
????????????????print(“No?checkpoint?file?found“)
????????????????return?-1

#預處理函數,包括resize,轉變灰度圖,二值化
def?pre_pic(picName):
????img?=?Image.open(picName)
????#用消除鋸齒的方法把原始圖片尺寸改為28*28
????reIm?=?img.resize((2828)Image.ANTIALIAS)
????#把圖片轉化為灰度圖并轉化為矩陣的形式賦值給im_arr
????im_arr?=?np.array(reIm.convert(‘L‘))
????#二值化處理
????threshold?=?50????#設置合理閾值
????for?i?in?range(28):
????????for?j?in?range(28):
????????????im_arr[i][j]?=?255?-?im_arr[i][j]
????????????if?(im_arr?????????????????im_arr[i][j]?=?0
????????????else:im_arr[i][j]?=?255

????nm_arr?=?im_arr.reshape([1784])
????nm_arr?=?nm_arr.astype(np.float32)
????#轉為0,1的浮點數
????img_ready?=?np.multiply(nm_arr1.0/255.0)

????return?img_ready

def?application():
????testNum?=?input(“Input?the?number?of?test?picture;“)
????for?i?in?range(testNum):
????????testPic?=?input(“The?path?of?test?picture:“)
????????testPicArr?=?pre_pic(testPic)
????????preValue?=?restore_model(testPicArr)
????????print(“the?prediction?number?is:“preValue)

def?main():
????application()

if?__name__?==?“__main__“:
????main()

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-03-16?19:45??mnist\
?????目錄???????????0??2019-03-16?19:45??mnist\.idea\
?????文件?????????138??2019-03-15?16:33??mnist\.idea\encodings.xml
?????目錄???????????0??2019-03-16?19:45??mnist\.idea\inspectionProfiles\
?????文件?????????306??2019-03-15?19:11??mnist\.idea\misc.xml
?????文件?????????649??2019-03-15?20:10??mnist\.idea\mnist.iml
?????文件?????????269??2019-03-15?19:10??mnist\.idea\modules.xml
?????文件?????????239??2019-03-15?20:10??mnist\.idea\other.xml
?????文件???????17597??2019-03-16?19:41??mnist\.idea\workspace.xml
?????目錄???????????0??2019-03-16?19:45??mnist\__pycache__\
?????文件?????????926??2019-03-15?17:27??mnist\__pycache__\forward.cpython-36.pyc
?????文件?????????932??2019-03-15?19:14??mnist\__pycache__\forward.cpython-37.pyc
?????文件????????2349??2019-03-16?16:42??mnist\appMnist.py
?????文件????????3060??2019-03-16?19:41??mnist\backward.py
?????文件?????????716??2019-03-15?19:14??mnist\forward.py
?????文件????????5574??2019-03-16?19:41??mnist\generateds.py
?????文件????????1912??2019-03-16?19:41??mnist\test.py

評論

共有 條評論