2

オブジェクト検出のためにスライディング ウィンドウ検索をベクトル化しようとしています。これまでのところ、numpy ブロードキャストを使用して、メイン イメージをウィンドウ サイズのスライスにスライスし、all_windows以下に示す変数に保存することができました。実際の値が一致することを確認したので、そこまでは満足しています。

次の部分は私が困っているところです。同様にベクトル化された形式で各ウィンドウを関数に渡すことができるようにall_windows、関数を呼び出すときに配列にインデックスを付けたいと思います。patchCleanNPredict()

([0,0]、[1,0]、[2,0]...) などの 2 次元配列にスライス インデックスを含む new_indx という配列を作成しようとしましたが、問題が発生しました。

各ウィンドウの信頼値の配列で終わることを望んでいます。以下のコードは、python 3.5 で動作します。ヘルプ/アドバイスをお寄せいただきありがとうございます。

import numpy as np

def patchCleanNPredict(patch):
    # patch = cv2.resize()# shrink patches with opencv resize function
    patch = np.resize(patch.flatten(),(1,np.shape(patch.flatten())[0])) # flatten the patch
    print('patch: ',patch.shape) 
    # confidence = predict(patch) # fake function showing prediction intent
    return # confidence


window = (30,46)# window dimensions
strideY = 10
strideX = 10

img = np.random.randint(0,245,(640,480)) # image that is being sliced by the windows

indx = np.arange(0,img.shape[0]-window[1],strideY)[:,None]+np.arange(window[1])
vertical_windows = img[indx]
print(vertical_windows.shape) # returns (60,46,480)


vertical_windows = np.transpose(vertical_windows,(0,2,1))
indx = np.arange(0,vertical_windows.shape[1]-window[0],strideX)[:,None]+np.arange(window[0])
all_windows = vertical_windows[0:vertical_windows.shape[0],indx]
all_windows = np.transpose(all_windows,(1,0,3,2))

print(all_windows.shape) # returns (45,60,46,30)


data_patch_size = (int(window[0]/2),int(window[1]/2)) # size the windows will be shrunk to

single_patch = all_windows[0,0,:,:]
patchCleanNPredict(single_patch) # prints the flattened patch size (1,1380)

new_indx = (1,1) # should this be an array of indices? 
patchCleanNPredict(all_windows[new_indx,:,:]) ## this is where I'm having trouble
4

1 に答える 1