下載inception v3 google訓練好的模型並解壓08-3


import tensorflow as tf
import os
import tarfile
import requests

#模型下載地址
inception_pretrain_model_url='http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'

#模型存放地址
inception_pretrain_model_dir="inception_model"
if not os.path.exists(inception_pretrain_model_dir):
    os.makedirs(inception_pretrain_model_dir)

#獲取文件名以及文件路徑
filename=inception_pretrain_model_url.split('/')[-1]
filepath=os.path.join(inception_pretrain_model_dir, filename)

#下載模型
if not os.path.exists(filepath):
    print("download:", filename)
    r=requests.get(inception_pretrain_model_url, stream=True)
    with open(filepath, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk:
                f.write(chunk)
print("finish: ",filename)
#解壓文件
tarfile.open(filepath, 'r:gz').extractall(inception_pretrain_model_dir)

#模型結構存放文件
log_dir='inception_log'
if not os.path.exists(log_dir):
    os.makedirs(log_dir)

#classify_image_graph_def.pb為google訓練好的模型
inception_graph_def_file=os.path.join(inception_pretrain_model_dir, 'classify_image_graph_def.pb')
with tf.Session() as sess:
    #創建一個圖來保存google訓練好的模型
    with tf.gfile.FastGFile(inception_graph_def_file, 'rb') as f:
        graph_def=tf.GraphDef()
        graph_def.ParseFromString(f.read())
        tf.import_graph_def(graph_def, name='')
    #保存圖的結構
    writer=tf.summary.FileWriter(log_dir, sess.graph)
    writer.close()

 這里使用了requests庫進行抓取並保存數據,如果要用py下載文件,都可以用這種方式進行下載;

使用tarfile庫進行解壓,使用tf.gfile tf.GraphDef()等進行圖的存儲。

 

百度網盤模型下載鏈接

提取碼: tgm7 

 

目錄:

  1. tensorflow簡介、目錄
  2. tensorflow中的圖(02-1)
  3. tensorflow變量的使用(02-2)
  4. tensorflow中的Fetch、Feed(02-3)
  5. tensorflow版helloworld---擬合線性函數的k和b(02-4)
  6. tensorflow非線性回歸(03-1)
  7. MNIST手寫數字分類simple版(03-2)
  8. 二次代價函數、交叉熵(cross-entropy)、對數似然代價函數(log-likelihood cost)(04-1)
  9. 多層網絡通過防止過擬合,增加模型的准確率(04-2)
  10. 修改優化器進一步提升准確率(04-3)
  11. 手寫數字識別-卷積神經網絡cnn(06-2)
  12. 循環神經網絡rnn與長短時記憶神經網絡簡述(07-2)
  13. 循環神經網絡lstm代碼實現(07-3)
  14. tensorflow模型保存和使用08
  15. 下載inception v3  google訓練好的模型並解壓08-3
  16. 使用inception v3做各種圖像分類識別08-4
  17. word2vec模型訓練簡單案例
  18. word2vec+textcnn文本分類簡述及代碼


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM