Beispiel #1
0
def main():
  img_size = 505

  gpu_id, net_path, model_path, img_paths = process_arguments(sys.argv)
  palette = pascal_palette_invert()
  net = Segmenter(net_path, model_path, gpu_id)

  for img_path in img_paths:
    img, cur_h, cur_w = preprocess_image(img_path, img_size)
    segm_result = net.predict([img])
    segm_post = postprocess_segmentation(segm_result, cur_h, cur_w, palette)
    
    concatenate = True
    segm_name = os.path.basename(img_path).split('.')[0]+'-label.png'
    save_result(segm_post, segm_name, concatenate, img_path)
Beispiel #2
0
def main():
    img_size = 505

    gpu_id, net_path, model_path, img_paths = process_arguments(sys.argv)
    palette = pascal_palette_invert()
    net = Segmenter(net_path, model_path, gpu_id)

    for img_path in img_paths:
        img, cur_h, cur_w = preprocess_image(img_path, img_size)
        segm_result = net.predict([img])
        segm_post = postprocess_segmentation(segm_result, cur_h, cur_w,
                                             palette)

        concatenate = True
        segm_name = os.path.basename(img_path).split('.')[0] + '-label.png'
        save_result(segm_post, segm_name, concatenate, img_path)
Beispiel #3
0
    def segment(self, image, slow=False):
        def predictor(X):
            X = np.expand_dims(X, axis=0)
            y = self.predict(X)
            y = np.squeeze(y, axis=0)
            return y

        if slow:
            input_height = self.S.image_height
            input_width = self.S.image_width
        else:
            _, input_height, input_width = image.shape

        segmenter = Segmenter(predictor,
                              self.S.image_depth,
                              input_height,
                              input_width,
                              image)
        return segmenter.predict()
Beispiel #4
0
def test_net(net_path, model_path, images, labels, lut, gpu_id):
  net = Segmenter(net_path, model_path, gpu_id)

  mean_vec = np.array([103.939, 116.779, 123.68], dtype=np.float32)
  reshaped_mean_vec = mean_vec.reshape(1, 1, 3);

  pa_list    = []
  ma_list    = []
  m_IU_list  = []
  fw_IU_list = []

  pb = ProgressBar(len(images))

  for img_path, label_path in zip(images, labels):
    im, cur_h, cur_w = preprocess_image(img_path, reshaped_mean_vec)
    label = imread(label_path)
    label = lut[label]

    segmentation = net.predict([im])
    pred = segmentation[0:cur_h, 0:cur_w]
   
    pa = pixel_accuracy(pred, label)
    ma = mean_accuracy(pred, label)
    m_IU = mean_IU(pred, label)
    fw_IU = frequency_weighted_IU(pred, label)

    pa_list.append(pa)
    ma_list.append(ma)
    m_IU_list.append(m_IU)
    fw_IU_list.append(fw_IU)

    pb.print_progress()

  print("pixel_accuracy: " + str(np.mean(pa_list)))
  print("mean_accuracy: " + str(np.mean(ma_list)))
  print("mean_IU: " + str(np.mean(m_IU_list)))
  print("frequency_weighted: " + str(np.mean(fw_IU_list)))