成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

python深度神經(jīng)網(wǎng)絡(luò)tensorflow練習(xí)好一點(diǎn)的實(shí)體模型開展圖像分類

89542767 / 391人閱讀

  此篇文章主要是給大家介紹了python深度神經(jīng)網(wǎng)絡(luò)tensorflow練習(xí)好一點(diǎn)的實(shí)體模型開展圖像分類實(shí)例詳細(xì)說明,感興趣的小伙伴可以參考借鑒一下,希望可以有一定的幫助,祝愿大家多多的發(fā)展,盡早漲薪。


  文章正文


  Google在各類圖象數(shù)據(jù)庫系統(tǒng)ImageNet上練習(xí)好啦1個(gè)Inception-v3實(shí)體模型,這一實(shí)體模型大家也可以用來進(jìn)去圖像分類。


  下載地址:https://pan.baidu.com/s/1XGfwYer5pIEDkpM3nM6o2A


  提取碼:hu66


  免費(fèi)下載完緩解壓力后,獲得好多個(gè)文檔:


  在其中


  classify_image_graph_def.pb文件便是練習(xí)好一點(diǎn)的Inception-v3實(shí)體模型。


  imagenet_synset_to_human_label_map.txt是類型文檔。


  隨機(jī)找一張圖片

01.png

  對(duì)這張圖片進(jìn)行識(shí)別,看它屬于什么類?


  代碼如下:先創(chuàng)建一個(gè)類NodeLookup來將softmax概率值映射到標(biāo)簽上。


  然后創(chuàng)建一個(gè)函數(shù)create_graph()來讀取模型。


  讀取圖片進(jìn)行分類識(shí)別


  #-*-coding:utf-8-*-
  import tensorflow as tf
  import numpy as np
  import re
  import os
  model_dir='D:/tf/model/'
  image='d:/cat.jpg'
  #將類別ID轉(zhuǎn)換為人類易讀的標(biāo)簽
  class NodeLookup(object):
  def __init__(self,
  label_lookup_path=None,
  uid_lookup_path=None):
  if not label_lookup_path:
  label_lookup_path=os.path.join(
  model_dir,'imagenet_2012_challenge_label_map_proto.pbtxt')
  if not uid_lookup_path:
  uid_lookup_path=os.path.join(
  model_dir,'imagenet_synset_to_human_label_map.txt')
  self.node_lookup=self.load(label_lookup_path,uid_lookup_path)
  def load(self,label_lookup_path,uid_lookup_path):
  if not tf.gfile.Exists(uid_lookup_path):
  tf.logging.fatal('File does not exist%s',uid_lookup_path)
  if not tf.gfile.Exists(label_lookup_path):
  tf.logging.fatal('File does not exist%s',label_lookup_path)
  #Loads mapping from string UID to human-readable string
  proto_as_ascii_lines=tf.gfile.GFile(uid_lookup_path).readlines()
  uid_to_human={}
  p=re.compile(r'[nd]*[S,]*')
  for line in proto_as_ascii_lines:
  parsed_items=p.findall(line)
  uid=parsed_items[0]
  human_string=parsed_items[2]
  uid_to_human[uid]=human_string
  #Loads mapping from string UID to integer node ID.
  node_id_to_uid={}
  proto_as_ascii=tf.gfile.GFile(label_lookup_path).readlines()
  for line in proto_as_ascii:
  if line.startswith('target_class:'):
  target_class=int(line.split(':')[1])
  if line.startswith('target_class_string:'):
  target_class_string=line.split(':')[1]
  node_id_to_uid[target_class]=target_class_string[1:-2]
  #Loads the final mapping of integer node ID to human-readable string
  node_id_to_name={}
  for key,val in node_id_to_uid.items():
  if val not in uid_to_human:
  tf.logging.fatal('Failed to locate:%s',val)
  name=uid_to_human[val]
  node_id_to_name[key]=name
  return node_id_to_name
  def id_to_string(self,node_id):
  if node_id not in self.node_lookup:
  return''
  return self.node_lookup[node_id]
  #讀取訓(xùn)練好的Inception-v3模型來創(chuàng)建graph
  def create_graph():
  with tf.gfile.FastGFile(os.path.join(
  model_dir,'classify_image_graph_def.pb'),'rb')as f:
  graph_def=tf.GraphDef()
  graph_def.ParseFromString(f.read())
  tf.import_graph_def(graph_def,name='')
  #讀取圖片
  image_data=tf.gfile.FastGFile(image,'rb').read()
  #創(chuàng)建graph
  create_graph()
  sess=tf.Session()
  #Inception-v3模型的最后一層softmax的輸出
  softmax_tensor=sess.graph.get_tensor_by_name('softmax:0')
  #輸入圖像數(shù)據(jù),得到softmax概率值(一個(gè)shape=(1,1008)的向量)
  predictions=sess.run(softmax_tensor,{'DecodeJpeg/contents:0':image_data})
  #(1,1008)->(1008,)
  predictions=np.squeeze(predictions)
  #ID-->English string label.
  node_lookup=NodeLookup()
  #取出前5個(gè)概率最大的值(top-5)
  top_5=predictions.argsort()[-5:][::-1]
  for node_id in top_5:
  human_string=node_lookup.id_to_string(node_id)
  score=predictions[node_id]
  print('%s(score=%.5f)'%(human_string,score))
  sess.close()

  最后輸出


  tiger cat(score=0.40316)


  Egyptian cat(score=0.21686)


  tabby,tabby cat(score=0.21348)


  lynx,catamount(score=0.01403)


  Persian cat(score=0.00394)


  綜上所述,上述就給大家介紹完畢了,希望可以給大家?guī)韼椭?/p>

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/128739.html

相關(guān)文章

  • caffe的python接口deploy形成caffemodel歸類新的圖片

      本文主要是給大家介紹了caffe的python插口生成deploy文件學(xué)習(xí)培訓(xùn)及其用練習(xí)好一點(diǎn)的實(shí)體模型(caffemodel)來歸類新的圖片實(shí)例詳細(xì)說明,感興趣的小伙伴可以參考借鑒一下,希望可以有一定的幫助,祝愿大家多多的發(fā)展,盡早漲薪  caffe的python插口生成deploy文件  假如要將練習(xí)好一點(diǎn)的實(shí)體模型用于檢測(cè)新的圖片,那必然必須得一個(gè)deploy.prototxt文件,這一...

    89542767 評(píng)論0 收藏0
  • 深度學(xué)習(xí)

    摘要:深度學(xué)習(xí)在過去的幾年里取得了許多驚人的成果,均與息息相關(guān)。機(jī)器學(xué)習(xí)進(jìn)階筆記之一安裝與入門是基于進(jìn)行研發(fā)的第二代人工智能學(xué)習(xí)系統(tǒng),被廣泛用于語音識(shí)別或圖像識(shí)別等多項(xiàng)機(jī)器深度學(xué)習(xí)領(lǐng)域。零基礎(chǔ)入門深度學(xué)習(xí)長短時(shí)記憶網(wǎng)絡(luò)。 多圖|入門必看:萬字長文帶你輕松了解LSTM全貌 作者 | Edwin Chen編譯 | AI100第一次接觸長短期記憶神經(jīng)網(wǎng)絡(luò)(LSTM)時(shí),我驚呆了。原來,LSTM是神...

    Vultr 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<