简体   繁体   English

使用预先训练的Inception_v4模型

[英]Using pre-trained Inception_v4 model

https://github.com/tensorflow/models/tree/master/slim https://github.com/tensorflow/models/tree/master/slim

This gives download link for checkpoints for Inception v1-4 pretrained models. 这为Inception v1-4预训练模型的检查点提供了下载链接。 However, the tar.gz contains only the .ckpt file. 但是,tar.gz只包含.ckpt文件。

In the tutorial on using Inception v3 2012 [This link] , the tar.gz contains .pb and .pbtxt files which are used for classification. 在使用Inception v3 2012 [此链接]的教程中,tar.gz包含用于分类的.pb和.pbtxt文件。

How can i use just the .ckpt file to generate respective .pb and .pbtxt files? 我如何只使用.ckpt文件生成相应的.pb和.pbtxt文件? OR Is there any alternate way of using the .ckpt file for classification? 或者是否有使用.ckpt文件进行分类的替代方法?

Even i am also trying inception_v4 model. 即使我也在尝试inception_v4模型。 During my search i could able to find the the checkpoint files contains the weights. 在我的搜索过程中,我能够找到包含权重的检查点文件。 So inorder to use this, inception_v4 graph needed to be loaded from inception_v4.py and the session needed to be restored from the checkpoint file. 因此,为了使用它,需要从inception_v4.py加载inception_v4图,并且需要从检查点文件恢复会话。 Following code will read the checkpoint file and create the protobuf file. 以下代码将读取检查点文件并创建protobuf文件。

import tensorflow as tf
slim = tf.contrib.slim
import tf_slim.models.slim.nets as net
# inception_v3_arg_scope
import tf_slim
import inception_v4 as net
import cv2


# checkpoint file
checkpoint_file = '/home/.../inception_v4.ckpt' 

# Load Session
sess = tf.Session()
arg_scope = net.inception_v4_arg_scope()
input_tensor = tf.placeholder(tf.float32, [None, 299, 299, 3])
with slim.arg_scope(arg_scope):
    logits, end_points = net.inception_v4(inputs=input_tensor)

saver = tf.train.Saver()
saver.restore(sess, checkpoint_file)
f = tf.gfile.FastGFile('./mynet.pb', "w")
f.write(sess.graph_def.SerializeToString())
f.close()

# reading the graph
#
with tf.gfile.FastGFile('./mynet.pb', 'rb') as fp:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(fp.read())

    with tf.Session(graph=tf.import_graph_def(graph_def, name='')) as sess:
    # op = sess.graph.get_operations()
    # with open('./tensors.txt', mode='w') as fp:
    #     for m in op:
    #     #     print m.values()
    #         fp.write('%s \n' % str(m.values()))
    cell_patch = cv2.imread('./car.jpg')
    softmax_tensor = sess.graph.get_tensor_by_name('InceptionV4/Logits/Predictions:0')
    predictions = sess.run(softmax_tensor, {'Placeholder:0': cell_patch})

But the above code wont give you the predictions. 但上面的代码不会给你预测。 Because I am facing problem in giving the input to the graph. 因为我在向图表提供输入时遇到问题。 But It can be of good starting point to work with checkpoint files. 但是使用检查点文件可能是一个很好的起点。

Checkpoint is downloaded from following link checkpoints 从以下链接检查点下载检查点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用预先训练的inception_resnet_v2和Tensorflow - Using pre-trained inception_resnet_v2 with Tensorflow 如何加载由 Google 命名为 inception 的预训练张量流模型? - How to load pre-trained tensorflow model named inception by Google? 使用预先训练的MaltParser模型和NLTK - Using pre-trained MaltParser model with NLTK 如何以Tensorflow格式下载并转换经过预训练的“ inception_v3”示例:? - how to download and convert a pre-trained “inception_v3” example in Tensorflow format:? 如何使Tensorflow教程中从Imagenet(classify_image.py)预训练的Inception-v3模型可作为模块导入? - How can I make the inception-v3 model pre-trained from Imagenet (classify_image.py) in the Tensorflow tutorial importable as a module? 使用预训练模型在张量流中训练新模型 - Using a pre-trained model to train a new model in tensor flow 在TensorflowServing中部署预先训练的Inception失败:SavedModel没有变量 - Deploy pre-trained Inception in TensorflowServing fails: SavedModel has no variables 在keras模型中使用预先训练的单词嵌入? - Using pre-trained word embeddings in a keras model? 在 Apache Flink 中使用预训练的 ML model - Using a pre-trained ML model in Apache Flink 在Keras的Alexnet模型中使用预先训练的权重 - Using pre-trained weights in Alexnet model in Keras
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM