2017-02-21 33 views
0

我試圖使用分類的人工神經網絡,我想嘗試的辦法是圖像:SIFT輸入到ANN

  1. 獲取特徵描述符使用神經(利用sift現在)
  2. 分類網絡

我爲此使用OpenCV3和Python。

我是比較新的機器學習,我有以下問題 -

,我分析將有不同數量的「關鍵點」和2D「描述」陣列的,因此不同尺寸的每個圖像。我如何決定我的ANN的輸入。例如,對於一個樣本圖像,描述符形狀爲(12211,128),所以我平坦化該數組並將其用作輸入,在這種情況下,我必須擔心每個圖像的變化輸入大小,還是計算其他值輸入?

+0

對於人工神經網絡,您通常需要固定尺寸的輸入。 –

回答

0

我不確定這是否是一個確切的解決方案,但這對我有效。主要思想如下:

  • 將你的圖像分成一個MxN網格。
  • 爲每個子圖像獲取一組特徵點。
  • 連接所有子圖像的結果以獲得整個圖像的特徵向量。

支撐代碼下面(函數 「pre_process_image」)大致給出:

def tiles(arr, nrows, ncols): 
    """ 
    If arr is a 2D array, the returned list contains nrowsXncols numpy arrays 
    with each array preserving the "physical" layout of arr. 

    When the array shape (rows, cols) are not divisible by (nrows, ncols) then 
    some of the array dimensions can change according to numpy.array_split. 

    """ 
    rows, cols, channel = arr.shape 
    col_arr = np.array_split(range(cols), ncols) 
    row_arr = np.array_split(range(rows), nrows) 
    return [arr[r[0]: r[-1]+1, c[0]: c[-1]+1] 
        for r, c in product(row_arr, col_arr)] 

def pre_process_images(data, dimensions=(28, 28)): 
    images = data['image'] 
    features = [] 
    count = 1 
    nrows = dimensions[0] 
    ncols = dimensions[1] 
    sift = cv2.xfeatures2d.SIFT_create(1) 
    for arr in images: 
     image_feature = [] 
     cut_image = tiles(arr, nrows, ncols) 
     for small_image in cut_image: 
      (kps, descs) = sift.detectAndCompute(im, None) 
      image_feature.append(descs.flatten()) 
     features.append(image_feature) 
     print count 
     count += 1 

    data['sift_features'] = features 
    return data 

然而,這是極其緩慢。我正在研究如何使用PCA以最佳方式選擇功能。

0

如果您在獲取特徵提取器之前在每個圖像上應用規範化,那將會很好。