'Load label image as 1 x height x width integer array of label indices.
The leading singleton dimension is required by the loss.'

def load_label(self, idx, label_type=None):

    if (label_type == 'semantic'):
        label = scipy.io.loadmat('{}/SemanticLabels/spatial_envelope_256x256_static_8outdoorcategories/{}.mat'.format(self.siftflow_dir, idx))['S']
    elif (label_type == 'geometric'):
        label = scipy.io.loadmat('{}/GeoLabels/spatial_envelope_256x256_static_8outdoorcategories/{}.mat'.format(self.siftflow_dir, idx))['S']
        label[(label == (-1))] = 0
    else:
        raise Exception('Unknown    label    type:    {}.    Pick    semantic    or    geometric.'.format(label_type))
    label = label.astype(np.uint8)
    label -= 1
    label = label[np.newaxis, ...]
    return label.copy()
