awoo
Browse filesSigned-off-by: Balazs Horvath <[email protected]>
dataset_tools/Create Empty txt Files for Images.ipynb
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\00a58ce07a5186d4edbe9eb29bd3fe53_1.txt\n",
|
13 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\044ce673a55771bd2b5700318547bb89.txt\n",
|
14 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\06b6dc04ce7e684216090f6a333a0f24.txt\n",
|
15 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\0b5371361af9d5706e010e6b91af8269.txt\n",
|
16 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\0b5ead570498882ea2c4f83970007faf.txt\n",
|
17 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\127ab13e2bb2c049e409eb7fdcbc9b7a.txt\n",
|
18 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\1308b781e85b8c64d7ee3ba1b64bf444.txt\n",
|
19 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\1ad66dc78c035d3241601072bb41a455.txt\n",
|
20 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\1caf765f1a0301e47680520dab472744.txt\n",
|
21 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\20aad729e70607539a47d0a2ccdf382b.txt\n",
|
22 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\2241b31138f5ada56d5e14ba371f82e7.txt\n",
|
23 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\22e6a9e62f29ac02ea1fbc78f6bd304f.txt\n",
|
24 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\24ea0ace58127a97cff268843615744f.txt\n",
|
25 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\2877886ddfdd0177f831dccb8e68aa4f.txt\n",
|
26 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\2e15a82de44733126b9982987f5badf1.txt\n",
|
27 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\2f9f20922622a03f1c94669a6f8c00f5.txt\n",
|
28 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\319aa3ba392b11796db84e266b58cd38.txt\n",
|
29 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\330d109c6b45475765563acb5780c44c.txt\n",
|
30 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\331101a6a21b450274b3b3e90d7593c6.txt\n",
|
31 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\33e345444a93860e274794d2dd3702a1.txt\n",
|
32 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\3439faa91c896be8787813572547b2a9.txt\n",
|
33 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\351af7711b3a57c84c0c28dfce9641b3.txt\n",
|
34 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\3cead9d7fccf871396db6f1986ad1188.txt\n",
|
35 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\42681e66733bdfd38800eb01c9b21522.txt\n",
|
36 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\4402451c6dc515356d25e10c620f2003.txt\n",
|
37 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\584a8f97df450c7742ecc1df77ed37fe.txt\n",
|
38 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\5ade980fb60341029c46d927948cffcc.txt\n",
|
39 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\5c6d81b6743953086bb1f6c7d2bbbd70_1.txt\n",
|
40 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\6c6f0b0fd01b8cf509e44bac38032a15.txt\n",
|
41 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\7051f37f3a100ecd09b8b704f7756fe3.txt\n",
|
42 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\744500bacde986871a6d4f464266a915.txt\n",
|
43 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\76fc8b8c80b70271f09c383c42da1d69.txt\n",
|
44 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\77aeebd0874339a181566c9d683ee0c0.txt\n",
|
45 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\79009dc71f54764093fc00fe30bfe1ec.txt\n",
|
46 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\82faee78f1ad3c32ca9045619c04d50e.txt\n",
|
47 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\856a37de0b35e336bc17bad772badc79.txt\n",
|
48 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\8b3e3bc11f014e3a9ad5ab2be648fc2c.txt\n",
|
49 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\90e06213e04da5adedeafbdb9cd365eb.txt\n",
|
50 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\94f4e009078007e3ed1051bf89de4034.txt\n",
|
51 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\9a104277b8f586d9090864bba6ffb4c3.txt\n",
|
52 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\9a1e5a6ebd91cc2263503c44f85b2335.txt\n",
|
53 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\9e995b2e5a51203aadade15076c3e43b.txt\n",
|
54 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\a1bb3892776dbaa41ebb9860f5173956.txt\n",
|
55 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\a3ddc2fbe220dc85b585294e1b7b355f.txt\n",
|
56 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\a493be0b29b9390f046795cbae93b0d5.txt\n",
|
57 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\a4fffd4a03a0bef737b7cfec5a8cc6f4.txt\n",
|
58 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\adbda3e546986a40f2476ef8f3e07118.txt\n",
|
59 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\afd1c3f2f8ea7693fb7a6cb692b50403.txt\n",
|
60 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\b5ca2054eb91296ba19809ae1d306b4d.txt\n",
|
61 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\b8f87e4deca6cbf37396e66447e31921.txt\n",
|
62 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\ba77c681986211c9b7da20b5050859a3.txt\n",
|
63 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\babaf50487ea84064971eb0d1757df23.txt\n",
|
64 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\bafc1dc4937f7ecf7cc707d32500b60d.txt\n",
|
65 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\c2b56828f5b306a9d1ef2f4970cb2a46.txt\n",
|
66 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\c8f28965c1bde921f89e7f7e49c0b078.txt\n",
|
67 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\d125439867ab61520cf8a5f9391a0cd9.txt\n",
|
68 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\d28945f8c9556d071028356457f16c34.txt\n",
|
69 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\d309a6abca98c989f24f3050c2a1bdd1.txt\n",
|
70 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\d709a20dff4ec44d84a446caac98d276.txt\n",
|
71 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\d756957fe6549e07e9b1236d36561bde.txt\n",
|
72 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\e1515ab206479a8673f14e1ae6fa66b0.txt\n",
|
73 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\eccdc7a822051408cab1f0e791e4e308.txt\n",
|
74 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\ecd6c90a0ea837644ca91faab0af71e0.txt\n",
|
75 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\f3062506cd9a84097f937f46181bfc4f.txt\n",
|
76 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\f82a37b693c9c6b626f1fe9b16840d3e.txt\n",
|
77 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\f873d55150075322fd60a47bdf940420.txt\n",
|
78 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\faaea9eccdc0e63abe7379fdf21d6fee.txt\n",
|
79 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\fdffb5c652d76e5ff33ab65d365b6802.txt\n",
|
80 |
+
"Created C:\\Users\\kade\\Desktop\\1_by_spaceengine\\fe5f1e6bd6a302b4830e34823a54bc34.txt\n"
|
81 |
+
]
|
82 |
+
}
|
83 |
+
],
|
84 |
+
"source": [
|
85 |
+
"import os\n",
|
86 |
+
"\n",
|
87 |
+
"def create_empty_txt_files(directory):\n",
|
88 |
+
" # Check if the directory exists\n",
|
89 |
+
" if not os.path.exists(directory):\n",
|
90 |
+
" print(\"Directory does not exist.\")\n",
|
91 |
+
" return\n",
|
92 |
+
" \n",
|
93 |
+
" # Get a list of all files in the directory\n",
|
94 |
+
" files = os.listdir(directory)\n",
|
95 |
+
" \n",
|
96 |
+
" # Iterate over each file\n",
|
97 |
+
" for file in files:\n",
|
98 |
+
" # Check if the file is an image (you can add more image extensions if needed)\n",
|
99 |
+
" if file.endswith(\".jpg\") or file.endswith(\".png\") or file.endswith(\".jpeg\"):\n",
|
100 |
+
" # Extract the filename without extension\n",
|
101 |
+
" filename = os.path.splitext(file)[0]\n",
|
102 |
+
" \n",
|
103 |
+
" # Create a corresponding txt file with the same name\n",
|
104 |
+
" txt_filename = os.path.join(directory, filename + \".txt\")\n",
|
105 |
+
" \n",
|
106 |
+
" # Check if the txt file already exists\n",
|
107 |
+
" if not os.path.exists(txt_filename):\n",
|
108 |
+
" # Create an empty txt file\n",
|
109 |
+
" with open(txt_filename, 'w') as f:\n",
|
110 |
+
" pass\n",
|
111 |
+
" print(f\"Created {txt_filename}\")\n",
|
112 |
+
" else:\n",
|
113 |
+
" print(f\"{txt_filename} already exists\")\n",
|
114 |
+
"\n",
|
115 |
+
"# Path to the directory containing the images\n",
|
116 |
+
"image_directory = r'C:\\Users\\kade\\Desktop\\1_by_spaceengine'\n",
|
117 |
+
"\n",
|
118 |
+
"# Call the function to create empty txt files\n",
|
119 |
+
"create_empty_txt_files(image_directory)"
|
120 |
+
]
|
121 |
+
}
|
122 |
+
],
|
123 |
+
"metadata": {
|
124 |
+
"kernelspec": {
|
125 |
+
"display_name": "Python 3",
|
126 |
+
"language": "python",
|
127 |
+
"name": "python3"
|
128 |
+
},
|
129 |
+
"language_info": {
|
130 |
+
"codemirror_mode": {
|
131 |
+
"name": "ipython",
|
132 |
+
"version": 3
|
133 |
+
},
|
134 |
+
"file_extension": ".py",
|
135 |
+
"mimetype": "text/x-python",
|
136 |
+
"name": "python",
|
137 |
+
"nbconvert_exporter": "python",
|
138 |
+
"pygments_lexer": "ipython3",
|
139 |
+
"version": "3.12.3"
|
140 |
+
}
|
141 |
+
},
|
142 |
+
"nbformat": 4,
|
143 |
+
"nbformat_minor": 2
|
144 |
+
}
|
dataset_tools/Rename images and captions to MD5.ipynb
CHANGED
@@ -11,19 +11,14 @@
|
|
11 |
},
|
12 |
{
|
13 |
"cell_type": "code",
|
14 |
-
"execution_count":
|
15 |
"metadata": {},
|
16 |
"outputs": [
|
17 |
{
|
18 |
-
"
|
19 |
-
"
|
20 |
-
"
|
21 |
-
|
22 |
-
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
23 |
-
"\u001b[1;31mFileExistsError\u001b[0m Traceback (most recent call last)",
|
24 |
-
"Cell \u001b[1;32mIn[10], line 34\u001b[0m\n\u001b[0;32m 31\u001b[0m directory \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mC:\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mUsers\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mkade\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mDesktop\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124m1_by_spaceengine\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m 33\u001b[0m \u001b[38;5;66;03m# Call the function to rename files\u001b[39;00m\n\u001b[1;32m---> 34\u001b[0m \u001b[43mrename_files\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdirectory\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 36\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFiles renamed successfully!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
25 |
-
"Cell \u001b[1;32mIn[10], line 22\u001b[0m, in \u001b[0;36mrename_files\u001b[1;34m(directory)\u001b[0m\n\u001b[0;32m 20\u001b[0m new_file_name \u001b[38;5;241m=\u001b[39m md5(file_path) \u001b[38;5;241m+\u001b[39m file_ext\u001b[38;5;241m.\u001b[39mlower()\n\u001b[0;32m 21\u001b[0m \u001b[38;5;66;03m# Rename image file\u001b[39;00m\n\u001b[1;32m---> 22\u001b[0m \u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrename\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpath\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mjoin\u001b[49m\u001b[43m(\u001b[49m\u001b[43mroot\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnew_file_name\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 23\u001b[0m \u001b[38;5;66;03m# Rename accompanying text files\u001b[39;00m\n\u001b[0;32m 24\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m ext \u001b[38;5;129;01min\u001b[39;00m (\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.txt\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.caption\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.tags\u001b[39m\u001b[38;5;124m'\u001b[39m):\n",
|
26 |
-
"\u001b[1;31mFileExistsError\u001b[0m: [WinError 183] Cannot create a file when that file already exists: 'C:\\\\Users\\\\kade\\\\Desktop\\\\1_by_spaceengine\\\\crop_p_color2_enhanced_release_small.png' -> 'C:\\\\Users\\\\kade\\\\Desktop\\\\1_by_spaceengine\\\\584a8f97df450c7742ecc1df77ed37fe.png'"
|
27 |
]
|
28 |
}
|
29 |
],
|
@@ -48,6 +43,15 @@
|
|
48 |
" if file_ext.lower() in ('.jpg', '.jpeg', '.png'):\n",
|
49 |
" # Calculate MD5 hash\n",
|
50 |
" new_file_name = md5(file_path) + file_ext.lower()\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
" # Rename image file\n",
|
52 |
" os.rename(file_path, os.path.join(root, new_file_name))\n",
|
53 |
" # Rename accompanying text files\n",
|
|
|
11 |
},
|
12 |
{
|
13 |
"cell_type": "code",
|
14 |
+
"execution_count": 11,
|
15 |
"metadata": {},
|
16 |
"outputs": [
|
17 |
{
|
18 |
+
"name": "stdout",
|
19 |
+
"output_type": "stream",
|
20 |
+
"text": [
|
21 |
+
"Files renamed successfully!\n"
|
|
|
|
|
|
|
|
|
|
|
22 |
]
|
23 |
}
|
24 |
],
|
|
|
43 |
" if file_ext.lower() in ('.jpg', '.jpeg', '.png'):\n",
|
44 |
" # Calculate MD5 hash\n",
|
45 |
" new_file_name = md5(file_path) + file_ext.lower()\n",
|
46 |
+
" # Check if the new filename already exists\n",
|
47 |
+
" if os.path.exists(os.path.join(root, new_file_name)):\n",
|
48 |
+
" # Add a suffix to make the filename unique\n",
|
49 |
+
" suffix = 1\n",
|
50 |
+
" while True:\n",
|
51 |
+
" new_file_name = md5(file_path) + '_' + str(suffix) + file_ext.lower()\n",
|
52 |
+
" if not os.path.exists(os.path.join(root, new_file_name)):\n",
|
53 |
+
" break\n",
|
54 |
+
" suffix += 1\n",
|
55 |
" # Rename image file\n",
|
56 |
" os.rename(file_path, os.path.join(root, new_file_name))\n",
|
57 |
" # Rename accompanying text files\n",
|