File size: 1,490 Bytes
39b6e8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 基础方法封装
import os
import shutil
import glob

# 绝对路径获取方法
curPath = os.path.dirname(os.path.abspath(__file__))
def getAbsPath (relativePath):
  joinPath = os.path.join(curPath, relativePath)
  return os.path.normpath(
    os.path.abspath(joinPath)
  )

# 数据集存放路径
datasets_dir = getAbsPath('./datasets')
if not shutil.os.path.exists(datasets_dir):
  shutil.os.makedirs(datasets_dir)

# 获取数据集列表 ----------------------------------------------------
def get_dataset_list():
  contents = os.listdir(datasets_dir)
  sub_dirs = [
    content
    for content in contents
    if os.path.isdir(os.path.join(datasets_dir, content))
  ]
  return sub_dirs

# 小模型存放路径
models_dir = getAbsPath('./models')
if not shutil.os.path.exists(models_dir):
  shutil.os.makedirs(models_dir)

# 获取模型列表 ----------------------------------------------------
def get_model_list():
  contents = os.listdir(models_dir)
  sub_dirs = [
    content
    for content in contents
    if os.path.isdir(os.path.join(models_dir, content))
  ]
  return sub_dirs

# 确保对应的空目录存在
def ensure_empty_dir(dirpath):
  if shutil.os.path.exists(dirpath):
    shutil.rmtree(dirpath)
  shutil.os.makedirs(dirpath)

# 获取目录中的最后一个文件
def get_last_file(dirpath):
  files = glob.glob(os.path.join(dirpath, '*'))
  sorted_files = sorted(files, key=os.path.basename)
  if sorted_files:
    return sorted_files[-1]
  return False