Răsfoiți Sursa

add get_folder_size

quarrying 4 ani în urmă
părinte
comite
ef4e54b5a8
2 a modificat fișierele cu 11 adăugiri și 0 ștergeri
  1. 1 0
      khandy/boxes/boxes_overlap.py
  2. 10 0
      khandy/utils_fs.py

+ 1 - 0
khandy/boxes/boxes_overlap.py

@@ -124,6 +124,7 @@ def pairwise_overlap_ratio(boxes1, boxes2, ratio_type='iou'):
                 that is, IOA(box1, box2) != IOA(box2, box1).
                 that is, IOA(box1, box2) != IOA(box2, box1).
             min: Compute the ratio as the area of intersection between box1 and box2, 
             min: Compute the ratio as the area of intersection between box1 and box2, 
                 divided by the minimum area of the two bounding boxes.
                 divided by the minimum area of the two bounding boxes.
+                
     Returns:
     Returns:
         a numpy array with shape [N, M] representing pairwise overlap ratio.
         a numpy array with shape [N, M] representing pairwise overlap ratio.
         
         

+ 10 - 0
khandy/utils_fs.py

@@ -139,6 +139,16 @@ def get_top_level_files(path, full_path=True):
                 if os.path.isfile(os.path.join(path_ex, item))]
                 if os.path.isfile(os.path.join(path_ex, item))]
                 
                 
 
 
+def get_folder_size(dirname):
+    if not os.path.exists(dirname):
+        raise ValueError("Incorrect path: {}".format(dirname))
+    total_size = 0
+    for root, _, filenames in os.walk(dirname):
+        for name in filenames:
+            total_size += os.path.getsize(os.path.join(root, name))
+    return total_size
+
+    
 def replace_invalid_filename_char(filename, new_char='_'):
 def replace_invalid_filename_char(filename, new_char='_'):
     assert isinstance(new_char, str)
     assert isinstance(new_char, str)
     control_chars = ''.join((map(chr, range(0x00, 0x20))))
     control_chars = ''.join((map(chr, range(0x00, 0x20))))