Repository: PaddlePaddle/PaddleSeg

Issue:
PaddleSeg训练报错
在aistudio 1.8.4环境下，训练中报错：

notebook里执行命令：
!python pdseg/train.py --use_gpu --cfg ./unet.yaml --do_eval --use_vdl --vdl_log_dir vdllog --log_steps 50 TRAIN.RESUME_MODEL_DIR  ./saved_model/unet/8  

报错信息：
#10000 visualize image path: visual/A155980.png
VisualDL visualization epoch 10
Traceback (most recent call last):
  File "pdseg/train.py", line 466, in <module>
    main(args)
  File "pdseg/train.py", line 453, in main
    train(cfg)
  File "pdseg/train.py", line 431, in train
    log_writer=log_writer)
  File "/home/aistudio/PaddleSeg/pdseg/vis.py", line 131, in visualize
    for imgs, grts, img_names, valid_shapes, org_shapes in test_reader:
  File "/home/aistudio/PaddleSeg/pdseg/reader.py", line 136, in batch_reader
    for img, grt, img_name, valid_shape, org_shape in reader():
  File "/home/aistudio/PaddleSeg/pdseg/reader.py", line 81, in generator
    yield self.process_image(line, self.data_dir, self.mode)
  File "/home/aistudio/PaddleSeg/pdseg/reader.py", line 251, in process_image
    line, data_dir, mode=mode)
  File "/home/aistudio/PaddleSeg/pdseg/reader.py", line 199, in load_image
    src_dir, img_path, grt_path))
UnboundLocalError: local variable 'grt_path' referenced before assignment


Discussion:

Resolving patch:
diff --git a/pdseg/reader.py b/pdseg/reader.py
--- a/pdseg/reader.py
+++ b/pdseg/reader.py
@@ -195,8 +195,7 @@ def load_image(self, line, src_dir, mode=ModelPhase.TRAIN):
 
         if img is None:
             raise Exception(
-                "Empty image, src_dir: {}, img: {} & lab: {}".format(
-                    src_dir, img_path, grt_path))
+                "Empty image, source image path: {}".format(img_path))
 
         img_height = img.shape[0]
         img_width = img.shape[1]
@@ -207,12 +206,12 @@ def load_image(self, line, src_dir, mode=ModelPhase.TRAIN):
 
             if img_height != grt_height or img_width != grt_width:
                 raise Exception(
-                    "source img and label img must has the same size")
+                    "Source img and label img must has the same size.")
         else:
             if mode == ModelPhase.TRAIN or mode == ModelPhase.EVAL:
                 raise Exception(
-                    "Empty image, src_dir: {}, img: {} & lab: {}".format(
-                        src_dir, img_path, grt_path))
+                    "No laber image path for image '{}' when training or evaluating. "
+                    .format(img_path))
 
         if len(img.shape) < 3:
             img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
@@ -226,12 +225,12 @@ def load_image(self, line, src_dir, mode=ModelPhase.TRAIN):
                 .format(img_channels, cfg.DATASET.DATADIM, img_name))
         if img_channels != len(cfg.MEAN):
             raise Exception(
-                "img name {}, img chns {} mean size {}, size unequal".format(
-                    img_name, img_channels, len(cfg.MEAN)))
+                "Image name {}, image channels {} do not equal the length of cfg.MEAN {}."
+                .format(img_name, img_channels, len(cfg.MEAN)))
         if img_channels != len(cfg.STD):
             raise Exception(
-                "img name {}, img chns {} std size {}, size unequal".format(
-                    img_name, img_channels, len(cfg.STD)))
+                "Image name {}, image channels {} do not equal the length of cfg.STD {}."
+                .format(img_name, img_channels, len(cfg.STD)))
 
         return img, grt, img_name, grt_name
 


Test patch: