zoukankan      html  css  js  c++  java
  • 【7-3下载google图像识别网络inception-v3并查看结构】

    参考程序:

     1 import tensorflow as tf
     2 import os
     3 import tarfile
     4 import requests
     5 
     6 #inception模型下载地址
     7 inception_pretrain_model_url = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'
     8 
     9 #模型存放地址
    10 inception_pretrain_model_dir = "inception_model"
    11 if not os.path.exists(inception_pretrain_model_dir):
    12     os.makedirs(inception_pretrain_model_dir)
    13     
    14 #获取文件名,以及文件路径
    15 filename = inception_pretrain_model_url.split('/')[-1]
    16 filepath = os.path.join(inception_pretrain_model_dir, filename)
    17 
    18 #下载模型
    19 if not os.path.exists(filepath):
    20     print("download: ", filename)
    21     r = requests.get(inception_pretrain_model_url, stream=True)
    22     with open(filepath, 'wb') as f:
    23         for chunk in r.iter_content(chunk_size=1024):
    24             if chunk:
    25                 f.write(chunk)
    26 print("finish: ", filename)
    27 #解压文件
    28 tarfile.open(filepath, 'r:gz').extractall(inception_pretrain_model_dir)
    29  
    30 #模型结构存放文件
    31 log_dir = 'inception_log'
    32 if not os.path.exists(log_dir):
    33     os.makedirs(log_dir)
    34 
    35 #classify_image_graph_def.pb为google训练好的模型
    36 inception_graph_def_file = os.path.join(inception_pretrain_model_dir, 'classify_image_graph_def.pb')
    37 with tf.Session() as sess:
    38     #创建一个图来存放google训练好的模型
    39     with tf.gfile.FastGFile(inception_graph_def_file, 'rb') as f:
    40         graph_def = tf.GraphDef()
    41         graph_def.ParseFromString(f.read())
    42         tf.import_graph_def(graph_def, name='')
    43     #保存图的结构
    44     writer = tf.summary.FileWriter(log_dir, sess.graph)
    45     writer.close()
    download:  inception-2015-12-05.tgz
    finish:  inception-2015-12-05.tgz

    程序运行之后,当前路径下生成了2个文件夹:

    文件夹中下载的压缩包和解压之后的文件:

    events文件,查看网络结构:

    输入命令行:

    2019-06-19 15:23:16

     

  • 相关阅读:
    H5 移动端相册拍照 录音 录像,然后上传后台
    h5 移动端调用相机 摄像机 录音机获取文件,并下载到本地
    Java 判断字符串是否含有 数字 字母 特殊字符
    java 以0开头的数字计算,保留开头0
    Spring 与hibernate 整合,测试数据连接
    http://blog.csdn.net/basycia/article/details/52205916
    MySQL数据库基础知识002
    数据库基础知识001
    数组排序
    输出杨辉三角
  • 原文地址:https://www.cnblogs.com/direwolf22/p/11051557.html
Copyright © 2011-2022 走看看