2016-06-16 8 views
0

テンソルフローを使用してこの問題を解決したいが、ウェブを検索してgit問題を発見した# 206では、インデクシングとスライスは、numpy配列から初期化されたテンソル変数ではまだサポートされていないことを示しています。テンソルフローを使用してイメージの前半部分をコピーして反転(lr)し、後半にコピーする

そうでなければ私は何を使用しなければならない...

image = mpimg.imread(filename) 
height, width, depth = image.shape 
x = tf.Variable(image, name='x') 
model = tf.initialize_all_variables() 

with tf.Session() as session: 
    session.run(model) 
    result = session.run(x[::1,:width*0.5,::1]) #this step is not possible 

を行っているでしょう?

+0

ドの最後の行使のためのソリューションです。ミラーリングされたイメージを生成するノードをTensorflowグラフに作成するか、結果をnumpy配列にしたいだけですか? –

+0

ノードは素晴らしいでしょう –

答えて

1

tf.slicetf.reverseを使用して、結果を連結する必要があります。

image = tf.placeholder(tf.float32, [height, width, depth]) 

half_left = tf.slice(image, [0, 0, 0], [height, width/2, depth]) 
half_right = tf.reverse(half_left, [False, True, False]) 

res = tf.concat(1, [half_left, half_right]) 

コードは変数でも動作します。私もここでは、テンソルフローのチュートリアルでは、1つのに苦労し

-1

はあなたが望むものを達成する全体のコードです:

import numpy as np 
import tensorflow as tf 
import matplotlib.image as mpimg 
import matplotlib.pyplot as plt 
import os 
# First, load the image again 
dir_path = os.path.dirname(os.path.realpath(__file__)) 
filename = dir_path + "/MarshOrchid.jpg" 
image = mpimg.imread(filename) 
height, width, depth = image.shape 

# Create a TensorFlow Variable 
x = tf.Variable(image, name='x') 


model = tf.global_variables_initializer() 

with tf.Session() as session: 
    session.run(model) 
    left_part = tf.slice(x, [0, 0, 0], [height, width/2, depth]) #Extract Left part 
    rigth_part = tf.slice(x, [0, width/2, 0], [height, width/2, depth]) #Extract Right part 
    left_part = tf.reverse_sequence(left_part, np.ones((height,)) * width/2, 1, batch_dim=0) #Reverse Left Part 
    rigth_part = tf.reverse_sequence(left_part, np.ones((height,)) * width/2, 1, batch_dim=0) #Reverse Right Part 
    x = tf.concat([left_part, rigth_part],1) #Concat them together along the second edge (the width) 

    result = session.run(x) 


print(result.shape) 
plt.imshow(result) 
plt.show() 

これらのコードはthis tutorial.

+0

これは新しい質問であれば [質問](/ questions/ask)ボタンをクリックして質問してください。 が役立つ場合は、この質問へのリンクを含めてください。これが答えであれば、もっと明確にしてください。 –

+0

**レビューキューから:**あなたの答えの周りにいくつかの文脈を追加してください。コードのみの回答は理解しにくいです。あなたの投稿にさらに情報を追加することができれば、これはAskerと将来の読者に役立ちます。 [コードベースの回答を完全に説明する](https://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)も参照してください。 –

関連する問題