This commit is contained in:
nguentrungthat 2025-03-21 14:57:23 +07:00
parent c1214662a3
commit f770973b5e
2 changed files with 48 additions and 41 deletions

View File

@ -311,9 +311,9 @@ function App() {
</Tabs.List> </Tabs.List>
</Box> </Box>
<Box className="px-4 flex items-center gap-4 w-fit"> <Box className="px-4 flex items-center gap-4 w-fit">
<Button disabled={isLoading} onClick={() => setOpenConfirm(true)} leftSection={<IconReportAnalytics size={14} />} color="#caa32c"> {/* <Button disabled={isLoading} onClick={() => setOpenConfirm(true)} leftSection={<IconReportAnalytics size={14} />} color="#caa32c">
Training Training
</Button> </Button> */}
<Button disabled={!clickData || isLoading} onClick={handleClearSelect} leftSection={<IconRefreshDot size={14} />} color="orange"> <Button disabled={!clickData || isLoading} onClick={handleClearSelect} leftSection={<IconRefreshDot size={14} />} color="orange">
Reset select Reset select
</Button> </Button>

View File

@ -15,6 +15,8 @@ IMAGE_EXTENSION = ".png"
LOG_FILE = "training_logs.log" LOG_FILE = "training_logs.log"
LATEST_DETECT_IMAGES = "latest_detect/images" LATEST_DETECT_IMAGES = "latest_detect/images"
LATEST_DETECT_LABELS = "latest_detect/labels" LATEST_DETECT_LABELS = "latest_detect/labels"
image_folder=""
label_folder=""
def get_label_names(): def get_label_names():
conn = sqlite3.connect("my_database.db") conn = sqlite3.connect("my_database.db")
@ -75,6 +77,7 @@ for folder in [train_img_folder, train_lbl_folder, val_img_folder, val_lbl_folde
# 📂 Get image list # 📂 Get image list
image_files = [f for f in os.listdir(image_folder) if f.endswith(IMAGE_EXTENSION)] image_files = [f for f in os.listdir(image_folder) if f.endswith(IMAGE_EXTENSION)]
label_files = [f for f in os.listdir(label_folder) if os.path.exists(label_folder)]
# 🌀 Shuffle images # 🌀 Shuffle images
random.shuffle(image_files) random.shuffle(image_files)
@ -86,6 +89,7 @@ split_idx = int(len(image_files) * train_ratio)
train_files = image_files[:split_idx] train_files = image_files[:split_idx]
val_files = image_files[split_idx:] val_files = image_files[split_idx:]
def copy_file_latest_training():
latest_img_folder = [f for f in os.listdir(LATEST_DETECT_IMAGES) if f.endswith(IMAGE_EXTENSION)] latest_img_folder = [f for f in os.listdir(LATEST_DETECT_IMAGES) if f.endswith(IMAGE_EXTENSION)]
train_files += latest_img_folder train_files += latest_img_folder
# Copy latest detect images to train folder # Copy latest detect images to train folder
@ -98,7 +102,6 @@ for img_file in latest_img_folder:
shutil.copy(img_path, os.path.join(image_folder, img_file)) shutil.copy(img_path, os.path.join(image_folder, img_file))
shutil.copy(label_path, os.path.join(label_folder, label_file)) shutil.copy(label_path, os.path.join(label_folder, label_file))
def log_message(message: str): def log_message(message: str):
"""Ghi log vào file""" """Ghi log vào file"""
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
@ -266,6 +269,9 @@ def train_yolo_model(
call_reload_model_api() call_reload_model_api()
clear_images_source() clear_images_source()
if(len(label_folder) >= 20):
copy_file_latest_training()
# 🚀 Copy files # 🚀 Copy files
train_copied_imgs, train_copied_lbls = move_files(train_files, train_img_folder, train_lbl_folder) train_copied_imgs, train_copied_lbls = move_files(train_files, train_img_folder, train_lbl_folder)
val_copied_imgs, val_copied_lbls = move_files(val_files, val_img_folder, val_lbl_folder) val_copied_imgs, val_copied_lbls = move_files(val_files, val_img_folder, val_lbl_folder)
@ -297,4 +303,5 @@ else:
name=today_str, name=today_str,
project_name=model_folder_name, project_name=model_folder_name,
) )
else:
log_message(f"Date: {today_str}. Need more image for training!!")