mirror of
https://github.com/azaion/ai-training.git
synced 2026-04-22 14:26:35 +00:00
copy images and labels during forming dataset. add folder for corrupted labels, small refactor
This commit is contained in:
+5
-26
@@ -50,13 +50,10 @@ def image_processing(img_ann: ImageLabel) -> [ImageLabel]:
|
||||
return results
|
||||
|
||||
|
||||
def write_result(img_ann: ImageLabel, show_image=False):
|
||||
def write_result(img_ann: ImageLabel):
|
||||
os.makedirs(os.path.dirname(img_ann.image_path), exist_ok=True)
|
||||
os.makedirs(os.path.dirname(img_ann.labels_path), exist_ok=True)
|
||||
|
||||
if show_image:
|
||||
img_ann.visualize(annotation_classes)
|
||||
|
||||
cv2.imencode('.jpg', img_ann.image)[1].tofile(img_ann.image_path)
|
||||
print(f'{img_ann.image_path} written')
|
||||
|
||||
@@ -92,28 +89,16 @@ def process_image(img_ann):
|
||||
image_path=os.path.join(processed_images_dir, Path(img_ann.image_path).name),
|
||||
labels_path=os.path.join(processed_labels_dir, Path(img_ann.labels_path).name)
|
||||
))
|
||||
# os.remove(img_ann.image_path)
|
||||
# os.remove(img_ann.labels_path)
|
||||
|
||||
|
||||
def main():
|
||||
checkpoint = datetime.now() - timedelta(days=720)
|
||||
try:
|
||||
with open(checkpoint_file, 'r') as f:
|
||||
checkpoint = datetime.strptime(f.read(), checkpoint_date_format)
|
||||
except:
|
||||
pass
|
||||
last_date = checkpoint
|
||||
while True:
|
||||
processed_images = set(f.name for f in os.scandir(processed_images_dir))
|
||||
images = []
|
||||
with os.scandir(data_images_dir) as imd:
|
||||
for image_file in imd:
|
||||
if not image_file.is_file():
|
||||
continue
|
||||
mod_time = datetime.fromtimestamp(image_file.stat().st_mtime)
|
||||
if mod_time > checkpoint:
|
||||
if image_file.is_file() and image_file.name not in processed_images:
|
||||
images.append(image_file)
|
||||
last_date = max(last_date, mod_time)
|
||||
|
||||
for image_file in images:
|
||||
try:
|
||||
@@ -128,14 +113,8 @@ def main():
|
||||
))
|
||||
except Exception as e:
|
||||
print(f'Error appeared {e}')
|
||||
if last_date != checkpoint:
|
||||
checkpoint = last_date
|
||||
try:
|
||||
with open(checkpoint_file, 'w') as f:
|
||||
f.write(datetime.strftime(checkpoint, checkpoint_date_format))
|
||||
except:
|
||||
pass
|
||||
time.sleep(5)
|
||||
print('All processed, waiting for 2 minutes...')
|
||||
time.sleep(120)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user