def predict(self, inputs):
# uses MEMORY_DATA layer for loading images and postprocessing DENSE_CRF layer
img = inputs[0].transpose((2, 0, 1))
img = img[np.newaxis, :].astype(np.float32)
label = np.zeros((1, 1, 1, 1), np.float32)
data_dim = np.zeros((1, 1, 1, 2), np.float32)
data_dim[0][0][0][0] = img.shape[2]
data_dim[0][0][0][1] = img.shape[3]
img = np.ascontiguousarray(img, dtype=np.float32)
label = np.ascontiguousarray(label, dtype=np.float32)
data_dim = np.ascontiguousarray(data_dim, dtype=np.float32)
self.set_input_arrays(img, label, data_dim)
out = self.forward()
predictions = out[self.outputs[0]] # the output layer should be called crf_inf
segm_result = predictions[0].argmax(axis=0).astype(np.uint8)
return segm_result
评论列表
文章目录