2016-10-11 10 views

答えて

5

まず、ネットワークアーキテクチャをメモリに取得しました。今、あなたは初期化することができ、これにより

from inception_resnet_v2 import inception_resnet_v2, inception_resnet_v2_arg_scope 

height = 299 
width = 299 
channels = 3 

X = tf.placeholder(tf.float32, shape=[None, height, width, channels]) 
with slim.arg_scope(inception_resnet_v2_arg_scope()): 
    logits, end_points = inception_resnet_v2(X, num_classes=1001,is_training=False) 

あなたはメモリ内のすべてのネットワークを持っている:あなたはあなたと一緒にこのプログラムを持っていたら、あなたはモデルを使用するには、次のアプローチを使用し、here

からネットワークアーキテクチャを得ることができますtf.train.saverを使用して、チェックポイントファイル(CKPT)とのネットワーク:あなたがボトルの特徴抽出を行いたい場合は

saver = tf.train.Saver() 
sess = tf.Session() 
saver.restore(sess, "/home/pramod/Downloads/inception_resnet_v2_2016_08_30.ckpt") 

は、のようなシンプルな、単にあなたが持っているそして、あなたは最後の層からフィーチャーを取得したいと言うことができます宣言するにはpredictions = end_points["Logits"]output = sess.run(predictions, feed_dict={X:batch_images})

+2

私はckptファイルと一緒に考えると、そのnetwork.metaファイルの.metaファイルを検索することもできますsaver = tf.train.import_meta_graph( 'The_model.meta')のように、tf.train.import()関数を使用してネットワークを再作成するのに使用されます。 –

+0

はい、できます。私は上記のネットワークの.metaファイルは見ていません。あなたがそのように出会ったなら、同じもののためのコメントのリンクをお願いします。 –

+0

tf.trainable_variables()は、訓練可能ではないにもかかわらず、開始モデルの変数もあまりにもリストしています。 – Tulsi

1

いいえ、そうではありません。

1.この

チェックポイントファイル(cpktファイル)を使用する方法についての記事( TensorFlow-Slim image classification library)は、次のスクラッチから

2.あなたのモデルを訓練する方法を説明しますから、サンプルコードですgoogle blog

import numpy as np 
import os 
import tensorflow as tf 
import urllib2 

from datasets import imagenet 
from nets import inception 
from preprocessing import inception_preprocessing 

slim = tf.contrib.slim 

batch_size = 3 
image_size = inception.inception_v3.default_image_size 

checkpoints_dir = '/root/code/model' 
checkpoints_filename = 'inception_resnet_v2_2016_08_30.ckpt' 
model_name = 'InceptionResnetV2' 
sess = tf.InteractiveSession() 
graph = tf.Graph() 
graph.as_default() 

def classify_from_url(url): 
    image_string = urllib2.urlopen(url).read() 
    image = tf.image.decode_jpeg(image_string, channels=3) 
    processed_image = inception_preprocessing.preprocess_image(image,  image_size, image_size, is_training=False) 
processed_images = tf.expand_dims(processed_image, 0) 

# Create the model, use the default arg scope to configure the batch norm parameters. 
with slim.arg_scope(inception.inception_resnet_v2_arg_scope()): 
    logits, _ = inception.inception_resnet_v2(processed_images, num_classes=1001, is_training=False) 
probabilities = tf.nn.softmax(logits) 

init_fn = slim.assign_from_checkpoint_fn(
    os.path.join(checkpoints_dir, checkpoints_filename), 
    slim.get_model_variables(model_name)) 

init_fn(sess) 
np_image, probabilities = sess.run([image, probabilities]) 
probabilities = probabilities[0, 0:] 
sorted_inds = [i[0] for i in sorted(enumerate(-probabilities), key=lambda x:x[1])] 

plt.figure() 
plt.imshow(np_image.astype(np.uint8)) 
plt.axis('off') 
plt.show() 

names = imagenet.create_readable_names_for_imagenet_labels() 
for i in range(5): 
    index = sorted_inds[i] 
    print('Probability %0.2f%% => [%s]' % (probabilities[index], names[index])) 
+0

の例もで事前に訓練されたモデルを使用しての下で見つけることができます:あなたは、他の中間層のためにそれを取得したい場合は、あなたが呼び出すことができますその後

inception_resnet_v2.py上記のプログラムからそれらの名前を得ることができます次のipythonのノートブック:https://github.com/tensorflow/models/blob/master/slim/slim_walkthrough.ipynb –

関連する問題