Repository: PaddlePaddle/PaddleSeg

Issue:
dataset数据加载异常
### 问题确认 Search before asking

- [X] 我已经查询[历史issue](https://github.com/PaddlePaddle/PaddleSeg/issues)(包括open与closed)，没有发现相似的bug。I have searched the [open and closed issues](https://github.com/PaddlePaddle/PaddleSeg/issues) and found no similar bug report.


### Bug描述 Describe the Bug

在“paddleseg/transforms/transforms.py”文件的“Compose”的__call__() 方法中，当cv2.imread()读取的数据不存在时，会引发“AttributeError: 'NoneType' object has no attribute 'astype'”异常，而对于读取的数据的判空操作位于astype操作之后，后续判断无法捕获NoneType引发的异常。
<img width="701" alt="Snipaste_2023-07-13_15-44-23" src="https://github.com/PaddlePaddle/PaddleSeg/assets/83578091/cc5b0fbf-5726-46c2-9175-36dc8fab163d">


### 复现环境 Environment

OS: Windows
PaddlePaddle: 2.2.2
PaddleSeg: release/2.8
Python: 3.9
CUDA:  11.3
CUDNN:  8.5.0


### Bug描述确认 Bug description confirmation

- [X] 我确认已经提供了Bug复现步骤、代码改动说明、以及环境信息，确认问题是可以复现的。I confirm that the bug replication steps, code change instructions, and environment information have been provided, and the problem can be reproduced.


### 是否愿意提交PR？ Are you willing to submit a PR?

- [X] 我愿意提交PR！I'd like to help by submitting a PR!


Discussion:
当数据集处理不规范时会引发此问题，即train/val_list.txt文件中路径索引所指向的图像被异常删除时会导致图像数据为空
感谢反馈，稍后会进行修复

Resolving patch:
diff --git a/paddleseg/transforms/transforms.py b/paddleseg/transforms/transforms.py
--- a/paddleseg/transforms/transforms.py
+++ b/paddleseg/transforms/transforms.py
@@ -31,7 +31,7 @@ class Compose:
     The shape of input data to all operations is [height, width, channels].
 
     Args:
-        transforms (list): A list contains data pre-processing or augmentation. Empty list means only reading images, no transformation.
+        transforms (list): A list contains data pre-processing or augmentation. An empty list means only reading images, no transformation.
         to_rgb (bool, optional): If converting image to RGB color space. Default: True.
         img_channels (int, optional): The image channels used to check the loaded image. Default: 3.
 
@@ -59,14 +59,18 @@ def __call__(self, data):
         """
         if 'img' not in data.keys():
             raise ValueError("`data` must include `img` key.")
-        if isinstance(data['img'], str):
-            data['img'] = cv2.imread(data['img'],
-                                     self.read_flag).astype('float32')
+        # data['img'] is numpy array in eg1800 and supervisely
         if data['img'] is None:
-            raise ValueError('Can\'t read The image file {}!'.format(data[
-                'img']))
+            raise TypeError(
+                "Expect `data[img]` to be str or np.ndarray, but got NoneType.")
+        elif isinstance(data['img'], str):
+            img = cv2.imread(data['img'], self.read_flag)
+            if img is None:
+                raise ValueError('Can\'t read The image file {}!'.format(data['img']))
+            data['img'] = img.astype('float32')
         if not isinstance(data['img'], np.ndarray):
-            raise TypeError("Image type is not numpy.")
+            raise TypeError(
+                "Expect image to be np.ndarray, but got {}".format(type(data['img'])))
 
         img_channels = 1 if data['img'].ndim == 2 else data['img'].shape[2]
         if img_channels != self.img_channels:


Test patch: