私はこのコードTensorflowインセプションresnet v2の入力テンソル
import os
import tensorflow as tf
from datasets import imagenet
from nets import inception_resnet_v2
from preprocessing import inception_preprocessing
checkpoints_dir = 'model'
slim = tf.contrib.slim
batch_size = 3
image_size = 299
with tf.Graph().as_default():
with slim.arg_scope(inception_resnet_v2.inception_resnet_v2_arg_scope()):
logits, _ = inception_resnet_v2.inception_resnet_v2([1, 299, 299, 3], num_classes=1001, is_training=False)
probabilities = tf.nn.softmax(logits)
init_fn = slim.assign_from_checkpoint_fn(
os.path.join(checkpoints_dir, 'inception_resnet_v2_2016_08_30.ckpt'),
slim.get_model_variables('InceptionResnetV2'))
with tf.Session() as sess:
init_fn(sess)
imgPath = '.../image_3.jpeg'
testImage_string = tf.gfile.FastGFile(imgPath, 'rb').read()
testImage = tf.image.decode_jpeg(testImage_string, channels=3)
np_image, probabilities = sess.run([testImage, probabilities])
probabilities = probabilities[0, 0:]
sorted_inds = [i[0] for i in sorted(enumerate(-probabilities), key=lambda x:x[1])]
names = imagenet.create_readable_names_for_imagenet_labels()
for i in range(15):
index = sorted_inds[i]
print((probabilities[index], names[index]))
を実行しようとしている。しかしTFは、エラーが表示されます。ValueError: rank of shape must be at least 4 not: 1
私はその問題は、入力テンソル形状[1, 299, 299, 3]
であると考えています。 3チャンネルのJPEG画像のテンソルを入力する方法は?
同様の質問もあります(Using pre-trained inception_resnet_v2 with Tensorflow)。私はコードinput_tensorで見ました - unfortunatelly説明は何ですかinput_tensor
です。たぶん私は何か自明であることを求めているが、私は立ち往生している!アドバイスをいただきありがとうございます。
あなたのtestImageベクトルが4次元の配列であることを確認できます – Julius
はい、testimageは4Dテンソルです。 'tf.Graph()。as_default()'の直後と '[1、299、299、3]の代わりに' imgPath、testImage_string、test_image'を書くと 'test_image'と書いても問題ないです。私の意図は、4Dの入力テンソルを手作業で入力して、セッションの部分でさまざまなイメージでモデルをテストすることです。 TF – Saddam