增加了训练时间!
This commit is contained in:
@@ -12,6 +12,7 @@ from torchvision import transforms
|
|||||||
from typing import List, Optional, Tuple
|
from typing import List, Optional, Tuple
|
||||||
from tkinterdnd2 import DND_FILES, TkinterDnD
|
from tkinterdnd2 import DND_FILES, TkinterDnD
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
# 设置customtkinter的外观
|
# 设置customtkinter的外观
|
||||||
ctk.set_appearance_mode("System")
|
ctk.set_appearance_mode("System")
|
||||||
@@ -90,6 +91,10 @@ class FoodClassifierApp:
|
|||||||
self.uploaded_images = []
|
self.uploaded_images = []
|
||||||
self.current_results = []
|
self.current_results = []
|
||||||
|
|
||||||
|
# 识别时间记录
|
||||||
|
self.recognition_start_time = None
|
||||||
|
self.recognition_duration = 0
|
||||||
|
|
||||||
# 模型相关
|
# 模型相关
|
||||||
self.model = None
|
self.model = None
|
||||||
self.transform = None
|
self.transform = None
|
||||||
@@ -500,6 +505,9 @@ class FoodClassifierApp:
|
|||||||
if result:
|
if result:
|
||||||
self.uploaded_images.clear()
|
self.uploaded_images.clear()
|
||||||
self.current_results.clear()
|
self.current_results.clear()
|
||||||
|
# 重置识别时间
|
||||||
|
self.recognition_start_time = None
|
||||||
|
self.recognition_duration = 0
|
||||||
self.update_images_display()
|
self.update_images_display()
|
||||||
self.update_recognize_button()
|
self.update_recognize_button()
|
||||||
self.update_results_display()
|
self.update_results_display()
|
||||||
@@ -518,6 +526,9 @@ class FoodClassifierApp:
|
|||||||
messagebox.showinfo("提示", "请先上传图片")
|
messagebox.showinfo("提示", "请先上传图片")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# 记录识别开始时间
|
||||||
|
self.recognition_start_time = time.time()
|
||||||
|
|
||||||
# 在新线程中执行识别,避免界面卡顿
|
# 在新线程中执行识别,避免界面卡顿
|
||||||
self.recognize_button.configure(state="disabled", text="识别中...")
|
self.recognize_button.configure(state="disabled", text="识别中...")
|
||||||
threading.Thread(target=self.recognize_images, daemon=True).start()
|
threading.Thread(target=self.recognize_images, daemon=True).start()
|
||||||
@@ -603,9 +614,13 @@ class FoodClassifierApp:
|
|||||||
|
|
||||||
def recognition_completed(self):
|
def recognition_completed(self):
|
||||||
"""识别完成"""
|
"""识别完成"""
|
||||||
|
# 计算识别耗时
|
||||||
|
if self.recognition_start_time is not None:
|
||||||
|
self.recognition_duration = time.time() - self.recognition_start_time
|
||||||
|
|
||||||
self.recognize_button.configure(state="normal", text="开始识别")
|
self.recognize_button.configure(state="normal", text="开始识别")
|
||||||
self.update_stats()
|
self.update_stats()
|
||||||
messagebox.showinfo("完成", "所有图片识别完成!")
|
messagebox.showinfo("完成", f"所有图片识别完成!识别耗时: {self.recognition_duration:.2f}秒")
|
||||||
|
|
||||||
def resize_image_for_display(self, image, max_width, max_height):
|
def resize_image_for_display(self, image, max_width, max_height):
|
||||||
"""调整图片大小用于显示"""
|
"""调整图片大小用于显示"""
|
||||||
@@ -756,10 +771,16 @@ class FoodClassifierApp:
|
|||||||
correct_count = sum(1 for r in auto_judged_results if r['is_correct'])
|
correct_count = sum(1 for r in auto_judged_results if r['is_correct'])
|
||||||
accuracy = (correct_count / len(auto_judged_results)) * 100
|
accuracy = (correct_count / len(auto_judged_results)) * 100
|
||||||
|
|
||||||
# 更新统计标签
|
# 构建统计文本,包含识别时间
|
||||||
|
if self.recognition_duration > 0:
|
||||||
|
stats_text = f"总图片: {total_images} | 已识别: {recognized_images} | 可判断: {len(auto_judged_results)} | 识别时间: {self.recognition_duration:.2f}秒 | 平均准确率: {accuracy:.1f}%"
|
||||||
|
else:
|
||||||
stats_text = f"总图片: {total_images} | 已识别: {recognized_images} | 可判断: {len(auto_judged_results)} | 平均准确率: {accuracy:.1f}%"
|
stats_text = f"总图片: {total_images} | 已识别: {recognized_images} | 可判断: {len(auto_judged_results)} | 平均准确率: {accuracy:.1f}%"
|
||||||
else:
|
else:
|
||||||
# 如果没有可自动判断的结果
|
# 如果没有可自动判断的结果
|
||||||
|
if self.recognition_duration > 0:
|
||||||
|
stats_text = f"总图片: {total_images} | 已识别: {recognized_images} | 可判断: 0 | 识别时间: {self.recognition_duration:.2f}秒 | 平均准确率: 0%"
|
||||||
|
else:
|
||||||
stats_text = f"总图片: {total_images} | 已识别: {recognized_images} | 可判断: 0 | 平均准确率: 0%"
|
stats_text = f"总图片: {total_images} | 已识别: {recognized_images} | 可判断: 0 | 平均准确率: 0%"
|
||||||
|
|
||||||
self.stats_label.configure(text=stats_text)
|
self.stats_label.configure(text=stats_text)
|
||||||
|
|||||||
Reference in New Issue
Block a user