1. 程式人生 > >FCN語義分割——直接載入影象資料

FCN語義分割——直接載入影象資料

前言

在之前的一篇部落格中我們使用了在Github上的程式碼進行語義分割,在進行訓練的時候Github上給出的是mat檔案型別的影象資料,這就很不方便了。這裡經過查閱相關資料之後發現不需要進行格式的轉換也可以進行訓練的。

修改過程

這裡還是用之前的部落格裡面提到的voc-fcn8s。開啟train.prototxt和val.prototxt之後可以看到這樣的層定義

layer {
  name: "data"
  type: "Python"
  top: "data"
  top: "label"
  python_param {
    module: "voc_layers"
    layer: "SBDDSegDataLayer"
    param_str: "{
\'sbdd_dir\': \'../data/sbdd/dataset\', \'seed\': 1337, \'split\': \'train\', \'mean\': (104.00699, 116.66877, 122.67892)}" } }

裡面的module指明瞭使用的python檔案,也就是用來進行資料匯入的。開啟它我們可以看到在類SBDDSegDataLayer的成員函式load_label使用到了mat檔案,如下

def load_label(self, idx):
    """
    Load label image as 1 x height x width integer array of label indices.
    The leading singleton dimension is required by the loss.
    """
import scipy.io mat = scipy.io.loadmat('{}/cls/{}.mat'.format(self.sbdd_dir, idx)) label = mat['GTcls'][0]['Segmentation'][0].astype(np.uint8) label = label[np.newaxis, ...] return label

將其修改為

def load_label(self, idx):
    """
    Load label image as 1 x height x width integer array of label indices.
    The leading singleton dimension is required by the loss.
    """
im = Image.open('{}/cls/{}.png'.format(self.sbdd_dir, idx)) label = np.array(im, dtype=np.uint8) label = label[np.newaxis, ...] return label

PS 之前應為沒有注意好影象的通道問題導致了CUBLAS_STATUS_MAPING_ERROR的問題
eeor
這裡是因為本人私自加了im= im.convert(‘L’)。導致引數不匹配,出現錯誤,將其刪除之後正常執行。類似的出現這種錯誤的原因主要為輸入引數範圍不匹配等造成的。