forked from josebenitezg/yolov8-streamlit-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
39 lines (30 loc) · 1.04 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
def get_subdirs(b='.'):
'''
Returns all sub-directories in a specific Path
'''
result = []
for d in os.listdir(b):
bd = os.path.join(b, d)
if os.path.isdir(bd):
result.append(bd)
return result
def get_detection_folder():
'''
Returns the latest folder in a runs\detect
'''
return max(get_subdirs(os.path.join('runs', 'detect')), key=os.path.getmtime)
def check_folders():
paths = {
'data_path' : 'data',
'images_path' : 'data/images',
'videos_path' : 'data/videos'
}
# Check whether the specified path exists or not
notExist = list(({file_type: path for (file_type, path) in paths.items() if not os.path.exists(path)}).values())
if notExist:
print(f'Folder {notExist} does not exist. We will created')
# Create a new directory because it does not exist
for folder in notExist:
os.makedirs(folder)
print(f"The new directory {folder} is created!")