zoukankan      html  css  js  c++  java
  • Tensorflow学习(练习)—下载骨骼图像识别网络inception数据集

    import tensorflow as tf
    import os
    import tarfile
    import requests

    #inception模型下载地址
    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()

    ##################运行结果

    download:  inception-2015-12-05.tgz
    finish:  inception-2015-12-05.tgz
  • 相关阅读:
    linux 软件 手动添加至桌面或启动栏
    memcached 技术支持
    linux mint & ubuntu 安装QQ国际版
    2014总结
    http response 过长 导致Connection reset
    Python高质量缩放切图,抗锯齿
    eclipse使用Maven插件创建一个web project
    springMVC or response redirect https
    使用SharedPreference保存一些简单的信息
    手机的sd卡的写入和读取数据的方
  • 原文地址:https://www.cnblogs.com/herd/p/9481983.html
Copyright © 2011-2022 走看看