tensorflowでsess.run()をする前に(マップを)作る段階で
アフィン変換する関数を作りたいです
その時、変換先の座標がテンソルになっていて配列の[]←の中に入れると以下のエラーが出ます。
*** IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
エラーには配列番号にはintegerのみを入れてくださいとあるのはわかりますが
テンソルをintに変える方法もありません。
コードは以下のようになっています。
python
1def shift_x_y(coords,H,W,B,image): 2 x_shift = tf.reshape(coords[:,:,:,0],[-1,H,W,B]) 3 y_shift = tf.reshape(coords[:,:,:,1],[-1,H,W,B]) 4 mag = tf.reshape(coords[:,:,:,2],[-1,H,W,B]) 5 6 for h in range(H): 7 for w in range(W): 8 x_ = x_shift[:,h,w,:] #<tf.Tensor 'strided_slice_4:0' shape=(?, 5) dtype=float32> 9 y_ = y_shift[:,h,w,:] #<tf.Tensor 'strided_slice_5:0' shape=(?, 5) dtype=float32> 10 mag_ = mag[:,h,w,:] #<tf.Tensor 'strided_slice_6:0' shape=(?, 5) dtype=float32> 11 12 new = np.ones((30,30))*255 13 for i in range(H): 14 for j in range(W): 15 new_x = mag_*i + x_ #<tf.Tensor 'add:0' shape=(?, 5) dtype=float32> 16 new_y = mag_*j + y_ #<tf.Tensor 'add_1:0' shape=(?, 5) dtype=float32> 17 #pdb.set_trace() 18 for k in range(B): 19 #new[tf.transpose(new_x)[k]][tf.transpose(new_y)[k]] = tf.cond(tf.transpose(new_x)[k]>W,lambda:) 20 """ 21 if tf.transpose(new_x)[k] > W: 22 pass 23 elif tf.transpose(newy)[k] > H: 24 pass 25 else: 26 new[tf.transpose(new_x)[k]][tf.transpose(new_y)[k]] = image[h][w][k][i][j] 27 """ 28 try: 29 new[tf.transpose(new_x)[k]][tf.transpose(new_y)[k]] = image[h][w][k][i][j] 30 print("success {0}".format(k)) 31 except: 32 pass 33 pdb.set_trace() 34 35 36 return 0
何か良い方法ないでしょうか
よろしくお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/27 07:14
2019/07/27 09:44
2019/07/27 12:01
2019/07/27 12:54