Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand Down Expand Up @@ -177,6 +177,18 @@
"from tensorflow.keras.utils import plot_model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Helper function to create a directory if it does not already exist\n",
"def ensure_dir(path):\n",
" if not os.path.exists(path):\n",
" os.makedirs(path)"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -284,15 +296,13 @@
"\n",
"pdf_path1 = \"./Padilla - Nobleza virtuosa_testExtract.pdf\" # Path to the PDF file\n",
"unproc_images_folder_1 = \"./preprocessing/imgsUnProcessed1\" # Output folder to save the images\n",
"if not os.path.exists(unproc_images_folder_1):\n",
" os.makedirs(unproc_images_folder_1)\n",
"ensure_dir(unproc_images_folder_1)\n",
"pdf_to_images(pdf_path1, unproc_images_folder_1)\n",
"\n",
"\n",
"pdf_path2 = \"./Padilla - 2 Noble perfecto_Extract.pdf\" # Path to the PDF file\n",
"unproc_images_folder_2 = \"./preprocessing/imgsUnProcessed2\" # Output folder to save the images\n",
"if not os.path.exists(unproc_images_folder_2):\n",
" os.makedirs(unproc_images_folder_2)\n",
"ensure_dir(unproc_images_folder_2)\n",
"pdf_to_images(pdf_path2, unproc_images_folder_2)"
]
},
Expand Down Expand Up @@ -339,15 +349,13 @@
"\n",
"unproc_images_folder_1 = \"./preprocessing/imgsUnProcessed1\"\n",
"proc_images_folder_1 = \"./preprocessing/imgsForAllPages1\"\n",
"if not os.path.exists(proc_images_folder_1):\n",
" os.makedirs(proc_images_folder_1)\n",
"ensure_dir(proc_images_folder_1)\n",
"process_images(unproc_images_folder_1, proc_images_folder_1)\n",
"\n",
"\n",
"unproc_images_folder_2 = \"./preprocessing/imgsUnProcessed2\"\n",
"proc_images_folder_2 = \"./preprocessing/imgsForAllPages2\"\n",
"if not os.path.exists(proc_images_folder_2):\n",
" os.makedirs(proc_images_folder_2)\n",
"ensure_dir(proc_images_folder_2)\n",
"process_images(unproc_images_folder_2, proc_images_folder_2)\n",
"\n",
"print(\"Image processing complete!\")"
Expand Down Expand Up @@ -459,14 +467,12 @@
"\n",
"bound_box_applied1 = './preprocessing/BoundBoxApplied1/'\n",
"bound_box_sorted1 = \"./preprocessing/BoundBoxSorted1\"\n",
"if not os.path.exists(bound_box_sorted1):\n",
" os.makedirs(bound_box_sorted1)\n",
"ensure_dir(bound_box_sorted1)\n",
"sort_bounding_boxes(bound_box_applied1, bound_box_sorted1)\n",
"\n",
"bound_box_applied2 = './preprocessing/BoundBoxApplied2/'\n",
"bound_box_sorted2 = \"./preprocessing/BoundBoxSorted2\"\n",
"if not os.path.exists(bound_box_sorted2):\n",
" os.makedirs(bound_box_sorted2)\n",
"ensure_dir(bound_box_sorted2)\n",
"sort_bounding_boxes(bound_box_applied2, bound_box_sorted2)"
]
},
Expand Down Expand Up @@ -546,17 +552,15 @@
"bound_box_sorted1 = './preprocessing/BoundBoxSorted1'\n",
"proc_grnd_truth1 = \"./preprocessing/textSplitted1\"\n",
"TEST_SIZE=6\n",
"if not os.path.exists(proc_grnd_truth1):\n",
" os.makedirs(proc_grnd_truth1)\n",
"ensure_dir(proc_grnd_truth1)\n",
"process_textfiles(grnd_truth1, bound_box_sorted1, proc_grnd_truth1, TEST_SIZE)\n",
"\n",
"\n",
"grnd_truth2 = \"./preprocessing/all_text2.txt\" \n",
"bound_box_sorted2 = './preprocessing/BoundBoxSorted2'\n",
"proc_grnd_truth2 = \"./preprocessing/textSplitted2\"\n",
"TEST_SIZE=0\n",
"if not os.path.exists(proc_grnd_truth2):\n",
" os.makedirs(proc_grnd_truth2)\n",
"ensure_dir(proc_grnd_truth2)\n",
"process_textfiles(grnd_truth2, bound_box_sorted2, proc_grnd_truth2, TEST_SIZE)\n",
"print(\"Text splitting complete!\")"
]
Expand Down Expand Up @@ -598,24 +602,22 @@
"proc_images_folder_1 = './preprocessing/imgsForAllPages1'\n",
"bound_box_sorted1 = './preprocessing/BoundBoxSorted1'\n",
"proc_grnd_truth1 = './preprocessing/textSplitted1'\n",
"training_data1 = './traning_data1'\n",
"training_data1 = './training_data1'\n",
"test_size=6\n",
"train_size = count_files_in_folder(proc_images_folder_1, ['.png', '.jpeg', '.jpg'])- test_size\n",
"print(\"Training pages \" + str(train_size))\n",
"if not os.path.exists(training_data1):\n",
" os.makedirs(training_data1)\n",
"ensure_dir(training_data1)\n",
"apply_extraction_to_folder_for_train(proc_images_folder_1, bound_box_sorted1, proc_grnd_truth1, training_data1, train_size)\n",
"\n",
"\n",
"proc_images_folder_2 = './preprocessing/imgsForAllPages2'\n",
"bound_box_sorted2 = './preprocessing/BoundBoxSorted2'\n",
"proc_grnd_truth2 = './preprocessing/textSplitted2'\n",
"training_data2 = './traning_data2'\n",
"training_data2 = './training_data2'\n",
"test_size = 0\n",
"train_size = count_files_in_folder(proc_images_folder_1, ['.png', '.jpeg', '.jpg'])- test_size\n",
"train_size = count_files_in_folder(proc_images_folder_2, ['.png', '.jpeg', '.jpg'])- test_size\n",
"print(\"Training pages \" + str(train_size))\n",
"if not os.path.exists(training_data2):\n",
" os.makedirs(training_data2)\n",
"ensure_dir(training_data2)\n",
"apply_extraction_to_folder_for_train(proc_images_folder_2, bound_box_sorted2, proc_grnd_truth2, training_data2, train_size) # better to send no. of pages given in transcription"
]
}
Expand Down
Loading