Procházet zdrojové kódy

[Fix] Clean chinese punctuation

geoyee před 3 roky
rodič
revize
354b8ea3a2

+ 9 - 10
paddlers/datasets/raster.py

@@ -27,25 +27,23 @@ class Raster:
     def __init__(self, 
                  path: str,
                  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.
 
         Args:
             path (str): The path of raster.
             band_list (Union[List[int], Tuple[int], None], optional): 
                 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__()
         if osp.exists(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.is_sar = is_sar
-            self.is_src = is_src
+            self.to_uint8 = to_uint8
             self.setBands(band_list)
         else:
             raise ValueError("The path {0} not exists.".format(path))
@@ -107,11 +105,12 @@ class Raster:
                 band_array.append(band_i)
             ima = np.stack(band_array, axis=0)
         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)
         else:
             ima = ima.transpose((1, 2, 0))
-        if self.is_src is False:
+        if self.to_uint8 is True:
             ima = raster2uint8(ima)
         return ima
 

+ 1 - 1
paddlers/tools/yolo_cluster.py

@@ -99,7 +99,7 @@ class YOLOAnchorCluster(BaseAnchorCluster):
             num_anchors (int): number of clusters
             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.
-            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.
             iters (int, optional): iters of kmeans algorithm. Defaults to 300.
             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.
 
-    AttentionIf interp is 'RANDOM', the interpolation method will be chose randomly.
+    Attention: If interp is 'RANDOM', the interpolation method will be chose randomly.
 
     Args:
         target_sizes (List[int], List[list or tuple] or Tuple[list or tuple]):
@@ -108,7 +108,7 @@ class BatchRandomResize(Transform):
 class BatchRandomResizeByShort(Transform):
     """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:
         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.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,6 +19,7 @@ import copy
 import random
 import imghdr
 from PIL import Image
+
 try:
     from collections.abc import Sequence
 except Exception:
@@ -103,7 +102,7 @@ class ImgDecode(Transform):
                 return cv2.imread(img_path, cv2.IMREAD_ANYDEPTH |
                                   cv2.IMREAD_ANYCOLOR | cv2.IMREAD_COLOR)
             else:
-                return cv2.imread(im_file, cv2.IMREAD_ANYDEPTH |
+                return cv2.imread(img_path, cv2.IMREAD_ANYDEPTH |
                                   cv2.IMREAD_ANYCOLOR)
         elif ext == '.npy':
             return np.load(img_path)

+ 8 - 8
paddlers/transforms/operators.py

@@ -204,9 +204,9 @@ class Resize(Transform):
     """
     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.
-    AttentionIf interp is 'RANDOM', the interpolation method will be chose randomly.
+    Attention: If interp is 'RANDOM', the interpolation method will be chose randomly.
 
     Args:
         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.
 
-    AttentionIf interp is 'RANDOM', the interpolation method will be chose randomly.
+    Attention: If interp is 'RANDOM', the interpolation method will be chose randomly.
 
     Args:
         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.
 
-    AttentionIf interp is 'RANDOM', the interpolation method will be chose randomly.
+    Attention: If interp is 'RANDOM', the interpolation method will be chose randomly.
 
     Args:
         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.
 
-    AttentionIf interp is 'RANDOM', the interpolation method will be chose randomly.
+    Attention: If interp is 'RANDOM', the interpolation method will be chose randomly.
 
     Args:
         short_sizes (List[int]): Target size of the shorter side of the image(s).
@@ -833,8 +833,8 @@ class RandomCrop(Transform):
 class RandomScaleAspect(Transform):
     """
     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.
         aspect_ratio (float): Aspect ratio of cropped region. Defaults to .33.
     """
@@ -1230,7 +1230,7 @@ class RandomBlur(Transform):
     """
     Randomly blur input image(s).
 
-    Args
+    Args: 
         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
 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):
-        # Get the corresponding gray level at 98% histogram
+        # get the corresponding gray level at 98% histogram
         high_value = np.percentile(gray, 98)
         low_value = np.percentile(gray, 2)
         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)
 
 
-# Simple image standardization
+# simple image standardization
 def _sample_norm(image: np.ndarray, NUMS: int=65536) -> np.ndarray:
     stretches = []
     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)
 
 
-# Histogram equalization
+# histogram equalization
 def _stretch(ima: np.ndarray, NUMS: int) -> np.ndarray:
     hist = _histogram(ima, NUMS)
     lut = []
     for bt in range(0, len(hist), NUMS):
-        # Step size
+        # step size
         step = reduce(operator.add, hist[bt : bt + NUMS]) / (NUMS - 1)
-        # Create balanced lookup table
+        # create balanced lookup table
         n = 0
         for i in range(NUMS):
             lut.append(n / step)
@@ -85,7 +85,7 @@ def _stretch(ima: np.ndarray, NUMS: int) -> np.ndarray:
         return ima
 
 
-# Calculate histogram
+# calculate histogram
 def _histogram(ima: np.ndarray, NUMS: int) -> np.ndarray:
     bins = list(range(0, NUMS))
     flat = ima.flat

+ 2 - 1
requirements.txt

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