{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Create Empty `.txt` Files For Images\n", "\n", "---" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Caption files created successfully.\n" ] } ], "source": [ "from pathlib import Path\n", "\n", "def create_caption_file(directory):\n", " for image_path in Path(directory).rglob('*'):\n", " if image_path.suffix.lower() in ['.jpg', '.jpeg', '.png']:\n", " caption_file = image_path.with_suffix('.txt')\n", " if not caption_file.exists():\n", " caption_file.touch()\n", "\n", "if __name__ == \"__main__\":\n", " directory = r'E:\\training_dir_staging'\n", " create_caption_file(directory)\n", " print(\"Caption files created successfully.\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create Empty `.caption` Files For Images\n", "\n", "---" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Caption files created successfully.\n" ] } ], "source": [ "from pathlib import Path\n", "\n", "def create_caption_file(directory):\n", " for image_path in Path(directory).rglob('*'):\n", " if image_path.suffix.lower() in ['.jpg', '.jpeg', '.png']:\n", " caption_file = image_path.with_suffix('.caption')\n", " if not caption_file.exists():\n", " caption_file.touch()\n", "\n", "if __name__ == \"__main__\":\n", " directory = r'E:\\training_dir_staging'\n", " create_caption_file(directory)\n", " print(\"Caption files created successfully.\")" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }