Commit ·
0e2d1b1
1
Parent(s): 3862abc
update
Browse files- images.parquet +2 -2
- regularization.parquet +2 -2
- src/build_parquet.py +7 -3
- src/update_dataset.py +0 -31
images.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:51fedecbd9a9a814e935128a3acfbb1322fe4f1463121a005674ee44d1b1b3b4
|
| 3 |
+
size 150783
|
regularization.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b014fb80b6378b0d3c3b056347d358141767422b2c0e229ded967d0e07791dd2
|
| 3 |
+
size 2761
|
src/build_parquet.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
import os
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
|
| 4 |
def get_dataset_directories(parent_dir='data/images/'):
|
| 5 |
directories = [os.path.join(parent_dir, dir) for dir in os.listdir(parent_dir) if os.path.isdir(os.path.join(parent_dir, dir))]
|
| 6 |
return directories
|
| 7 |
|
|
|
|
| 8 |
def package_multiple_directories(directories, output_file):
|
| 9 |
data = []
|
| 10 |
for directory in directories:
|
|
@@ -12,11 +14,13 @@ def package_multiple_directories(directories, output_file):
|
|
| 12 |
for file in os.listdir(directory):
|
| 13 |
if file.endswith(('.png', '.jpg', '.jpeg')):
|
| 14 |
name = os.path.splitext(file)[0]
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
with open(os.path.join(directory, name + '.txt'), 'r') as txt_file:
|
| 17 |
caption = txt_file.read().strip()
|
| 18 |
-
data.append([name, class_name,
|
| 19 |
-
df = pd.DataFrame(data, columns=["name", "class", "
|
| 20 |
df.to_parquet(output_file)
|
| 21 |
|
| 22 |
def main():
|
|
|
|
| 1 |
import os
|
| 2 |
import pandas as pd
|
| 3 |
+
import base64
|
| 4 |
|
| 5 |
def get_dataset_directories(parent_dir='data/images/'):
|
| 6 |
directories = [os.path.join(parent_dir, dir) for dir in os.listdir(parent_dir) if os.path.isdir(os.path.join(parent_dir, dir))]
|
| 7 |
return directories
|
| 8 |
|
| 9 |
+
|
| 10 |
def package_multiple_directories(directories, output_file):
|
| 11 |
data = []
|
| 12 |
for directory in directories:
|
|
|
|
| 14 |
for file in os.listdir(directory):
|
| 15 |
if file.endswith(('.png', '.jpg', '.jpeg')):
|
| 16 |
name = os.path.splitext(file)[0]
|
| 17 |
+
image_path = os.path.join(directory, file)
|
| 18 |
+
with open(image_path, 'rb') as image_file:
|
| 19 |
+
image_data = base64.b64encode(image_file.read()).decode('utf-8')
|
| 20 |
with open(os.path.join(directory, name + '.txt'), 'r') as txt_file:
|
| 21 |
caption = txt_file.read().strip()
|
| 22 |
+
data.append([name, class_name, image_data, caption])
|
| 23 |
+
df = pd.DataFrame(data, columns=["name", "class", "image", "caption"])
|
| 24 |
df.to_parquet(output_file)
|
| 25 |
|
| 26 |
def main():
|
src/update_dataset.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import csv
|
| 3 |
-
|
| 4 |
-
def get_dataset_directories(parent_dir='data/images/'):
|
| 5 |
-
directories = [os.path.join(parent_dir, dir) for dir in os.listdir(parent_dir) if os.path.isdir(os.path.join(parent_dir, dir))]
|
| 6 |
-
return directories
|
| 7 |
-
|
| 8 |
-
def generate_csv(directory):
|
| 9 |
-
csv_data = []
|
| 10 |
-
class_name = os.path.basename(directory).replace('1_', '')
|
| 11 |
-
for file in os.listdir(directory):
|
| 12 |
-
if file.endswith(('.png', '.jpg', '.jpeg')):
|
| 13 |
-
name = os.path.splitext(file)[0]
|
| 14 |
-
image = file
|
| 15 |
-
with open(os.path.join(directory, name + '.txt'), 'r') as txt_file:
|
| 16 |
-
caption = txt_file.read().strip()
|
| 17 |
-
csv_data.append([name, class_name, image, caption])
|
| 18 |
-
with open(os.path.join(directory, 'metadata.csv'), 'w', newline='') as csv_file:
|
| 19 |
-
writer = csv.writer(csv_file)
|
| 20 |
-
writer.writerow(["name", "class", "image", "caption"])
|
| 21 |
-
writer.writerows(csv_data)
|
| 22 |
-
|
| 23 |
-
def main():
|
| 24 |
-
directories = get_dataset_directories()
|
| 25 |
-
for directory in directories:
|
| 26 |
-
generate_csv(directory)
|
| 27 |
-
print(directory)
|
| 28 |
-
generate_csv('data/regularization')
|
| 29 |
-
|
| 30 |
-
if __name__ == "__main__":
|
| 31 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|