瀏覽代碼

[Fix] Clean chinese punctuation

geoyee 3 年之前
父節點
當前提交
354b8ea3a2

+ 9 - 10
paddlers/datasets/raster.py

@@ -27,25 +27,23 @@ class Raster:
     def __init__(self, 
     def __init__(self, 
                  path: str,
                  path: str,
                  band_list: Union[List[int], Tuple[int], None]=None, 
                  band_list: Union[List[int], Tuple[int], None]=None, 
-                 is_sar: bool=False,  # TODO: Remove this param
-                 is_src: bool=False) -> None:
+                 to_uint8: bool=False) -> None:
         """ Class of read raster.
         """ Class of read raster.
 
 
         Args:
         Args:
             path (str): The path of raster.
             path (str): The path of raster.
             band_list (Union[List[int], Tuple[int], None], optional): 
             band_list (Union[List[int], Tuple[int], None], optional): 
                 band list (start with 1) or None (all of bands). Defaults to None.
                 band list (start with 1) or None (all of bands). Defaults to None.
-            is_sar (bool, optional): The raster is SAR or not. Defaults to False.
-            is_src (bool, optional): 
-                Return raw data or not (convert uint8/float32). Defaults to False.
+            to_uint8 (bool, optional): 
+                Convert uint8 or return raw data. Defaults to False.
         """
         """
         super(Raster, self).__init__()
         super(Raster, self).__init__()
         if osp.exists(path):
         if osp.exists(path):
             self.path = path
             self.path = path
-            self.__src_data = gdal.Open(path)
+            self.__src_data = np.load(path) if path.split(".")[-1] == "npy" \
+                                            else gdal.Open(path)
             self.__getInfo()
             self.__getInfo()
-            self.is_sar = is_sar
-            self.is_src = is_src
+            self.to_uint8 = to_uint8
             self.setBands(band_list)
             self.setBands(band_list)
         else:
         else:
             raise ValueError("The path {0} not exists.".format(path))
             raise ValueError("The path {0} not exists.".format(path))
@@ -107,11 +105,12 @@ class Raster:
                 band_array.append(band_i)
                 band_array.append(band_i)
             ima = np.stack(band_array, axis=0)
             ima = np.stack(band_array, axis=0)
         if self.bands == 1:
         if self.bands == 1:
-            if self.is_sar:
+            # the type is complex means this is a SAR data
+            if isinstance(type(ima[0, 0]), complex):
                 ima = abs(ima)
                 ima = abs(ima)
         else:
         else:
             ima = ima.transpose((1, 2, 0))
             ima = ima.transpose((1, 2, 0))
-        if self.is_src is False:
+        if self.to_uint8 is True:
             ima = raster2uint8(ima)
             ima = raster2uint8(ima)
         return ima
         return ima
 
 

+ 1 - 1
paddlers/tools/yolo_cluster.py

@@ -99,7 +99,7 @@ class YOLOAnchorCluster(BaseAnchorCluster):
             num_anchors (int): number of clusters
             num_anchors (int): number of clusters
             dataset (DataSet): DataSet instance, VOC or COCO
             dataset (DataSet): DataSet instance, VOC or COCO
             image_size (list or int): [h, w], being an int means image height and image width are the same.
             image_size (list or int): [h, w], being an int means image height and image width are the same.
-            cache (bool): whether using cache Defaults to True.
+            cache (bool): whether using cache. Defaults to True.
             cache_path (str or None, optional): cache directory path. If None, use `data_dir` of dataset. Defaults to None.
             cache_path (str or None, optional): cache directory path. If None, use `data_dir` of dataset. Defaults to None.
             iters (int, optional): iters of kmeans algorithm. Defaults to 300.
             iters (int, optional): iters of kmeans algorithm. Defaults to 300.
             gen_iters (int, optional): iters of genetic algorithm. Defaults to 1000.
             gen_iters (int, optional): iters of genetic algorithm. Defaults to 1000.

+ 2 - 2
paddlers/transforms/batch_operators.py

@@ -69,7 +69,7 @@ class BatchRandomResize(Transform):
     """
     """
     Resize a batch of input to random sizes.
     Resize a batch of input to random sizes.
 
 
-    AttentionIf interp is 'RANDOM', the interpolation method will be chose randomly.
+    Attention: If interp is 'RANDOM', the interpolation method will be chose randomly.
 
 
     Args:
     Args:
         target_sizes (List[int], List[list or tuple] or Tuple[list or tuple]):
         target_sizes (List[int], List[list or tuple] or Tuple[list or tuple]):
@@ -108,7 +108,7 @@ class BatchRandomResize(Transform):
 class BatchRandomResizeByShort(Transform):
 class BatchRandomResizeByShort(Transform):
     """Resize a batch of input to random sizes with keeping the aspect ratio.
     """Resize a batch of input to random sizes with keeping the aspect ratio.
 
 
-    AttentionIf interp is 'RANDOM', the interpolation method will be chose randomly.
+    Attention: If interp is 'RANDOM', the interpolation method will be chose randomly.
 
 
     Args:
     Args:
         short_sizes (List[int], Tuple[int]): Target sizes of the shorter side of the image(s).
         short_sizes (List[int], Tuple[int]): Target sizes of the shorter side of the image(s).

+ 2 - 3
paddlers/transforms/img_decoder.py

@@ -1,5 +1,3 @@
-
-   
 # copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
 # copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
 #
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,6 +19,7 @@ import copy
 import random
 import random
 import imghdr
 import imghdr
 from PIL import Image
 from PIL import Image
+
 try:
 try:
     from collections.abc import Sequence
     from collections.abc import Sequence
 except Exception:
 except Exception:
@@ -103,7 +102,7 @@ class ImgDecode(Transform):
                 return cv2.imread(img_path, cv2.IMREAD_ANYDEPTH |
                 return cv2.imread(img_path, cv2.IMREAD_ANYDEPTH |
                                   cv2.IMREAD_ANYCOLOR | cv2.IMREAD_COLOR)
                                   cv2.IMREAD_ANYCOLOR | cv2.IMREAD_COLOR)
             else:
             else:
-                return cv2.imread(im_file, cv2.IMREAD_ANYDEPTH |
+                return cv2.imread(img_path, cv2.IMREAD_ANYDEPTH |
                                   cv2.IMREAD_ANYCOLOR)
                                   cv2.IMREAD_ANYCOLOR)
         elif ext == '.npy':
         elif ext == '.npy':
             return np.load(img_path)
             return np.load(img_path)

+ 8 - 8
paddlers/transforms/operators.py

@@ -204,9 +204,9 @@ class Resize(Transform):
     """
     """
     Resize input.
     Resize input.
 
 
-    - If target_size is an intresize the image(s) to (target_size, target_size).
+    - If target_size is an int, resize the image(s) to (target_size, target_size).
     - If target_size is a list or tuple, resize the image(s) to target_size.
     - If target_size is a list or tuple, resize the image(s) to target_size.
-    AttentionIf interp is 'RANDOM', the interpolation method will be chose randomly.
+    Attention: If interp is 'RANDOM', the interpolation method will be chose randomly.
 
 
     Args:
     Args:
         target_size (int, List[int] or Tuple[int]): Target size. If int, the height and width share the same target_size.
         target_size (int, List[int] or Tuple[int]): Target size. If int, the height and width share the same target_size.
@@ -315,7 +315,7 @@ class RandomResize(Transform):
     """
     """
     Resize input to random sizes.
     Resize input to random sizes.
 
 
-    AttentionIf interp is 'RANDOM', the interpolation method will be chose randomly.
+    Attention: If interp is 'RANDOM', the interpolation method will be chose randomly.
 
 
     Args:
     Args:
         target_sizes (List[int], List[list or tuple] or Tuple[list or tuple]):
         target_sizes (List[int], List[list or tuple] or Tuple[list or tuple]):
@@ -356,7 +356,7 @@ class ResizeByShort(Transform):
     """
     """
     Resize input with keeping the aspect ratio.
     Resize input with keeping the aspect ratio.
 
 
-    AttentionIf interp is 'RANDOM', the interpolation method will be chose randomly.
+    Attention: If interp is 'RANDOM', the interpolation method will be chose randomly.
 
 
     Args:
     Args:
         short_size (int): Target size of the shorter side of the image(s).
         short_size (int): Target size of the shorter side of the image(s).
@@ -395,7 +395,7 @@ class RandomResizeByShort(Transform):
     """
     """
     Resize input to random sizes with keeping the aspect ratio.
     Resize input to random sizes with keeping the aspect ratio.
 
 
-    AttentionIf interp is 'RANDOM', the interpolation method will be chose randomly.
+    Attention: If interp is 'RANDOM', the interpolation method will be chose randomly.
 
 
     Args:
     Args:
         short_sizes (List[int]): Target size of the shorter side of the image(s).
         short_sizes (List[int]): Target size of the shorter side of the image(s).
@@ -833,8 +833,8 @@ class RandomCrop(Transform):
 class RandomScaleAspect(Transform):
 class RandomScaleAspect(Transform):
     """
     """
     Crop input image(s) and resize back to original sizes.
     Crop input image(s) and resize back to original sizes.
-    Args
-        min_scale (float)Minimum ratio between the cropped region and the original image.
+    Args: 
+        min_scale (float): Minimum ratio between the cropped region and the original image.
             If 0, image(s) will not be cropped. Defaults to .5.
             If 0, image(s) will not be cropped. Defaults to .5.
         aspect_ratio (float): Aspect ratio of cropped region. Defaults to .33.
         aspect_ratio (float): Aspect ratio of cropped region. Defaults to .33.
     """
     """
@@ -1230,7 +1230,7 @@ class RandomBlur(Transform):
     """
     """
     Randomly blur input image(s).
     Randomly blur input image(s).
 
 
-    Args
+    Args: 
         prob (float): Probability of blurring.
         prob (float): Probability of blurring.
     """
     """
 
 

+ 6 - 6
paddlers/utils/convert.py

@@ -39,7 +39,7 @@ def raster2uint8(image: np.ndarray) -> np.ndarray:
 # 2% linear stretch
 # 2% linear stretch
 def _two_percentLinear(image: np.ndarray, max_out: int=255, min_out: int=0) -> np.ndarray:
 def _two_percentLinear(image: np.ndarray, max_out: int=255, min_out: int=0) -> np.ndarray:
     def _gray_process(gray, maxout=max_out, minout=min_out):
     def _gray_process(gray, maxout=max_out, minout=min_out):
-        # Get the corresponding gray level at 98% histogram
+        # get the corresponding gray level at 98% histogram
         high_value = np.percentile(gray, 98)
         high_value = np.percentile(gray, 98)
         low_value = np.percentile(gray, 2)
         low_value = np.percentile(gray, 2)
         truncated_gray = np.clip(gray, a_min=low_value, a_max=high_value)
         truncated_gray = np.clip(gray, a_min=low_value, a_max=high_value)
@@ -55,7 +55,7 @@ def _two_percentLinear(image: np.ndarray, max_out: int=255, min_out: int=0) -> n
     return np.uint8(result)
     return np.uint8(result)
 
 
 
 
-# Simple image standardization
+# simple image standardization
 def _sample_norm(image: np.ndarray, NUMS: int=65536) -> np.ndarray:
 def _sample_norm(image: np.ndarray, NUMS: int=65536) -> np.ndarray:
     stretches = []
     stretches = []
     if len(image.shape) == 3:
     if len(image.shape) == 3:
@@ -69,14 +69,14 @@ def _sample_norm(image: np.ndarray, NUMS: int=65536) -> np.ndarray:
     return np.uint8(stretched_img * 255)
     return np.uint8(stretched_img * 255)
 
 
 
 
-# Histogram equalization
+# histogram equalization
 def _stretch(ima: np.ndarray, NUMS: int) -> np.ndarray:
 def _stretch(ima: np.ndarray, NUMS: int) -> np.ndarray:
     hist = _histogram(ima, NUMS)
     hist = _histogram(ima, NUMS)
     lut = []
     lut = []
     for bt in range(0, len(hist), NUMS):
     for bt in range(0, len(hist), NUMS):
-        # Step size
+        # step size
         step = reduce(operator.add, hist[bt : bt + NUMS]) / (NUMS - 1)
         step = reduce(operator.add, hist[bt : bt + NUMS]) / (NUMS - 1)
-        # Create balanced lookup table
+        # create balanced lookup table
         n = 0
         n = 0
         for i in range(NUMS):
         for i in range(NUMS):
             lut.append(n / step)
             lut.append(n / step)
@@ -85,7 +85,7 @@ def _stretch(ima: np.ndarray, NUMS: int) -> np.ndarray:
         return ima
         return ima
 
 
 
 
-# Calculate histogram
+# calculate histogram
 def _histogram(ima: np.ndarray, NUMS: int) -> np.ndarray:
 def _histogram(ima: np.ndarray, NUMS: int) -> np.ndarray:
     bins = list(range(0, NUMS))
     bins = list(range(0, NUMS))
     flat = ima.flat
     flat = ima.flat

+ 2 - 1
requirements.txt

@@ -8,9 +8,10 @@ paddleslim == 2.2.1
 shapely
 shapely
 paddlepaddle-gpu >= 2.2.0
 paddlepaddle-gpu >= 2.2.0
 opencv-python
 opencv-python
-scikit-learn==0.20.3
+scikit-learn == 0.20.3
 lap
 lap
 motmetrics
 motmetrics
 matplotlib
 matplotlib
 chardet
 chardet
 openpyxl
 openpyxl
+GDAL >= 3.2.2