Fu-Chuen commited on
Commit
690fa46
·
1 Parent(s): 62e20c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -62,8 +62,7 @@ project_path = Path('./')
62
  model_path = Path(project_path,'Model')
63
  test_path = Path(project_path,'Test')
64
  os.makedirs(test_path, exist_ok=True)
65
- image_path = Path(project_path,'runs/detect/predict')
66
- label_path = Path(image_path,'labels')
67
  weight_path = Path(model_path,'best_Yolo_v8n.pt')
68
  # 指定工作目录
69
  # working_directory = '/home/user/app'
@@ -162,14 +161,13 @@ def delete_files_in_folder(path):
162
  file_path = os.path.join(root, file)
163
  os.remove(file_path)
164
 
165
- # command = [
166
- # "pip3",
167
- # "install",
168
- # "--no-cache-dir",
169
- # "transformers"
170
- # ]
171
- # run_subprocess(command)
172
-
173
  def Aspergillus_Detect():
174
  delete_files_in_folder(image_path)
175
  # get_all_files(working_directory)
@@ -177,7 +175,10 @@ def Aspergillus_Detect():
177
  model = YOLO(weight_path) # pretrained YOLOv8n model
178
 
179
  model.predict(test_path, save = True , save_txt = True ) # predict on an image
180
- get_all_files(working_directory)
 
 
 
181
 
182
  file_paths = []
183
  for root, dirs, files in os.walk(label_path):
 
62
  model_path = Path(project_path,'Model')
63
  test_path = Path(project_path,'Test')
64
  os.makedirs(test_path, exist_ok=True)
65
+ detect_path = Path(project_path,'runs/detect')
 
66
  weight_path = Path(model_path,'best_Yolo_v8n.pt')
67
  # 指定工作目录
68
  # working_directory = '/home/user/app'
 
161
  file_path = os.path.join(root, file)
162
  os.remove(file_path)
163
 
164
+ def find_the_most_recent_predict_path(path):
165
+ path = list(map(lambda x: x.split('/'),path))
166
+ path = [i for i in path if 'predict' in i[-1]]
167
+ # Sort the list by the last element of each inner list
168
+ path = sorted(path, key=lambda x: x[-1])
169
+ return '/'.join(path[-1])
170
+
 
171
  def Aspergillus_Detect():
172
  delete_files_in_folder(image_path)
173
  # get_all_files(working_directory)
 
175
  model = YOLO(weight_path) # pretrained YOLOv8n model
176
 
177
  model.predict(test_path, save = True , save_txt = True ) # predict on an image
178
+ all_files, all_directories = get_all_files(working_directory)
179
+
180
+ image_path = Path(find_the_most_recent_predict_path(all_directories))
181
+ label_path = Path(image_path,'labels')
182
 
183
  file_paths = []
184
  for root, dirs, files in os.walk(label_path):