k4d3 commited on
Commit
74f1f95
1 Parent(s): a2322be
dataset_tools/Create Empty caption Files for Images.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 2,
6
  "metadata": {},
7
  "outputs": [
8
  {
@@ -25,20 +25,17 @@
25
  }
26
  ],
27
  "source": [
28
- "import os\n",
29
  "\n",
30
  "def create_caption_file(directory):\n",
31
- " for root, dirs, files in os.walk(directory):\n",
32
- " for file in files:\n",
33
- " if file.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
34
- " image_path = os.path.join(root, file)\n",
35
- " caption_file = os.path.splitext(image_path)[0] + \".caption\"\n",
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'C:\\Users\\kade\\Desktop\\training_dir_staging'\n",
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.2"
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,