awoo
Browse files
dataset_tools/Create Empty caption Files for Images.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
@@ -25,20 +25,17 @@
|
|
25 |
}
|
26 |
],
|
27 |
"source": [
|
28 |
-
"import
|
29 |
"\n",
|
30 |
"def create_caption_file(directory):\n",
|
31 |
-
" for
|
32 |
-
"
|
33 |
-
"
|
34 |
-
"
|
35 |
-
" caption_file
|
36 |
-
" if not os.path.exists(caption_file):\n",
|
37 |
-
" with open(caption_file, 'w'):\n",
|
38 |
-
" pass\n",
|
39 |
"\n",
|
40 |
"if __name__ == \"__main__\":\n",
|
41 |
-
" directory = r'
|
42 |
" create_caption_file(directory)\n",
|
43 |
" print(\"Caption files created successfully.\")"
|
44 |
]
|
@@ -60,7 +57,7 @@
|
|
60 |
"name": "python",
|
61 |
"nbconvert_exporter": "python",
|
62 |
"pygments_lexer": "ipython3",
|
63 |
-
"version": "3.12.
|
64 |
}
|
65 |
},
|
66 |
"nbformat": 4,
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
|
|
25 |
}
|
26 |
],
|
27 |
"source": [
|
28 |
+
"from pathlib import Path\n",
|
29 |
"\n",
|
30 |
"def create_caption_file(directory):\n",
|
31 |
+
" for image_path in Path(directory).rglob('*'):\n",
|
32 |
+
" if image_path.suffix.lower() in ['.jpg', '.jpeg', '.png']:\n",
|
33 |
+
" caption_file = image_path.with_suffix('.caption')\n",
|
34 |
+
" if not caption_file.exists():\n",
|
35 |
+
" caption_file.touch()\n",
|
|
|
|
|
|
|
36 |
"\n",
|
37 |
"if __name__ == \"__main__\":\n",
|
38 |
+
" directory = r'E:\\training_dir_staging'\n",
|
39 |
" create_caption_file(directory)\n",
|
40 |
" print(\"Caption files created successfully.\")"
|
41 |
]
|
|
|
57 |
"name": "python",
|
58 |
"nbconvert_exporter": "python",
|
59 |
"pygments_lexer": "ipython3",
|
60 |
+
"version": "3.12.3"
|
61 |
}
|
62 |
},
|
63 |
"nbformat": 4,
|