mirror of
https://github.com/azaion/ai-training.git
synced 2026-04-22 11:26:36 +00:00
small fix
add code for revert dataset add get_recent_model
This commit is contained in:
@@ -36,8 +36,11 @@ def move_annotations(images, folder):
|
|||||||
image_path = os.path.join(current_images_dir, image_name)
|
image_path = os.path.join(current_images_dir, image_name)
|
||||||
label_name = f'{Path(image_name).stem}.txt'
|
label_name = f'{Path(image_name).stem}.txt'
|
||||||
label_path = os.path.join(current_labels_dir, label_name)
|
label_path = os.path.join(current_labels_dir, label_name)
|
||||||
os.replace(image_path, os.path.join(destination_images, image_name))
|
if not os.path.exists(label_path):
|
||||||
os.replace(label_path, os.path.join(destination_labels, label_name))
|
os.remove(image_path)
|
||||||
|
else:
|
||||||
|
os.replace(image_path, os.path.join(destination_images, image_name))
|
||||||
|
os.replace(label_path, os.path.join(destination_labels, label_name))
|
||||||
|
|
||||||
|
|
||||||
def create_yaml():
|
def create_yaml():
|
||||||
@@ -55,18 +58,17 @@ def create_yaml():
|
|||||||
|
|
||||||
|
|
||||||
def get_recent_model():
|
def get_recent_model():
|
||||||
date_sets = []
|
cur_model = None
|
||||||
datasets = [next((file for file in os.listdir(os.path.join('datasets', d)) if file.endswith('pt')), None)
|
cur_date = None
|
||||||
for d in os.listdir('datasets')]
|
for d in os.listdir('datasets'):
|
||||||
|
date_str = d.replace(prefix, '')
|
||||||
# date_str = d.replace(prefix, '')
|
if date_str == 'current' or date_str == f'{datetime.now():%Y-%m-%d}':
|
||||||
# if date_str == 'current' or date_str == f'{datetime.now():%Y-%m-%d}':
|
continue
|
||||||
# continue
|
date = datetime.strptime(date_str, '%Y-%m-%d')
|
||||||
# if len(date_sets) == 0:
|
for file in os.listdir(os.path.join('datasets', d)):
|
||||||
# return None
|
if file.endswith('pt') and cur_date is None or cur_date < date:
|
||||||
|
cur_model = os.path.join('datasets', d, file)
|
||||||
recent = max(date_sets)
|
return cur_model
|
||||||
return os.path.join('datasets', f'{prefix}{recent}', f'{prefix}{recent}.pt')
|
|
||||||
|
|
||||||
|
|
||||||
def retrain():
|
def retrain():
|
||||||
@@ -75,12 +77,19 @@ def retrain():
|
|||||||
|
|
||||||
|
|
||||||
def revert_to_current(date):
|
def revert_to_current(date):
|
||||||
def revert_dir(dir):
|
def revert_dir(src_dir, dest_dir):
|
||||||
os.listdir(os.path.join(current_images_dir, 'images'))
|
for file in os.listdir(src_dir):
|
||||||
|
s = os.path.join(src_dir, file)
|
||||||
|
d = os.path.join(dest_dir, file)
|
||||||
|
os.replace(s, d)
|
||||||
|
date_dataset = os.path.join('datasets', f'{prefix}{date}')
|
||||||
|
current_dataset = os.path.join('datasets', f'{prefix}current')
|
||||||
|
for subset in ['test', 'train', 'valid']:
|
||||||
|
revert_dir(os.path.join(date_dataset, subset, 'images'), os.path.join(current_dataset, 'images'))
|
||||||
|
revert_dir(os.path.join(date_dataset, subset, 'labels'), os.path.join(current_dataset, 'labels'))
|
||||||
|
shutil.rmtree(date_dataset)
|
||||||
|
|
||||||
date_dataset = f'{prefix}{date}'
|
|
||||||
revert_dir(os.path.join(date_dataset, 'test'))
|
|
||||||
|
|
||||||
form_dataset()
|
form_dataset()
|
||||||
create_yaml()
|
# revert_to_current('2024-06-06')
|
||||||
retrain()
|
retrain()
|
||||||
|
|||||||
Reference in New Issue
Block a user