Datasets:
Add images
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- convert.py +64 -0
- meta.txt +9 -0
- original/.DS_Store +0 -0
- original/test/.DS_Store +0 -0
- original/test/.gitattributes +0 -0
- original/test/r31/r31-0001.png +3 -0
- original/test/r31/r31-0002.png +3 -0
- original/test/r31/r31-0003.png +3 -0
- original/test/r31/r31-0004.png +3 -0
- original/test/r31/r31-0005.png +3 -0
- original/test/r31/r31-0006.png +3 -0
- original/test/r31/r31-0007.png +3 -0
- original/test/r31/r31-0008.png +3 -0
- original/test/r31/r31-0009.png +3 -0
- original/test/r31/r31-0010.png +3 -0
- original/test/r31/r31-0011.png +3 -0
- original/test/r31/r31-0012.png +3 -0
- original/test/r31/r31-0013.png +3 -0
- original/test/r31/r31-0014.png +3 -0
- original/test/r31/r31-0015.png +3 -0
- original/test/r31/r31-0016.png +3 -0
- original/test/r31/r31-0017.png +3 -0
- original/test/r31/r31-0018.png +3 -0
- original/test/r31/r31-0019.png +3 -0
- original/test/r31/r31-0020.png +3 -0
- original/test/r31/r31-0021.png +3 -0
- original/test/r31/r31-0022.png +3 -0
- original/test/r31/r31-0023.png +3 -0
- original/test/r31/r31-0024.png +3 -0
- original/test/r31/r31-0025.png +3 -0
- original/test/r31/r31-0026.png +3 -0
- original/test/r31/r31-0027.png +3 -0
- original/test/r31/r31-0028.png +3 -0
- original/test/r31/r31-0029.png +3 -0
- original/test/r31/r31-0030.png +3 -0
- original/test/r31/r31-0031.png +3 -0
- original/test/r31/r31-0032.png +3 -0
- original/test/r31/r31-0033.png +3 -0
- original/test/r31/r31-0034.png +3 -0
- original/test/r31/r31-0035.png +3 -0
- original/test/r31/r31-0036.png +3 -0
- original/test/r31/r31-0037.png +3 -0
- original/test/r31/r31-0038.png +3 -0
- original/test/r31/r31-0039.png +3 -0
- original/test/r31/r31-0040.png +3 -0
- original/test/r31/r31-0041.png +3 -0
- original/test/r31/r31-0042.png +3 -0
- original/test/r31/r31-0043.png +3 -0
- original/test/r31/r31-0044.png +3 -0
- original/test/r31/r31-0045.png +3 -0
convert.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import pandas as pd
|
3 |
+
from PIL import Image
|
4 |
+
import codecs
|
5 |
+
import numpy as np
|
6 |
+
import glob
|
7 |
+
|
8 |
+
def create_dataset():
|
9 |
+
print("Starting dataset creation...")
|
10 |
+
|
11 |
+
# Create output directory for images
|
12 |
+
os.makedirs("processed_images", exist_ok=True)
|
13 |
+
|
14 |
+
# Find all label files matching pattern
|
15 |
+
print("Finding label files...")
|
16 |
+
label_files = glob.glob("./original/test/round3?_best2019.label")
|
17 |
+
print(f"Found {len(label_files)} label files")
|
18 |
+
|
19 |
+
# Parse image filenames and captions
|
20 |
+
data = []
|
21 |
+
for i, label_path in enumerate(label_files):
|
22 |
+
print(f"\nProcessing label file {i+1}/{len(label_files)}: {label_path}")
|
23 |
+
|
24 |
+
# Read label file with Windows-874 encoding
|
25 |
+
print("Reading label file...")
|
26 |
+
with codecs.open(label_path, 'r', encoding='cp874') as f:
|
27 |
+
lines = f.readlines()
|
28 |
+
print(f"Found {len(lines)} entries")
|
29 |
+
|
30 |
+
for j, line in enumerate(lines):
|
31 |
+
if j % 100 == 0:
|
32 |
+
print(f"Processing entry {j}/{len(lines)}")
|
33 |
+
|
34 |
+
filename, caption = line.strip().split(' ', 1)
|
35 |
+
|
36 |
+
# Get folder name from first 3 chars of filename
|
37 |
+
folder = filename[:3]
|
38 |
+
image_path = f"./original/test/{folder}/{filename}"
|
39 |
+
|
40 |
+
# Load and verify image exists
|
41 |
+
if os.path.exists(image_path):
|
42 |
+
try:
|
43 |
+
# Save image to processed directory and store path
|
44 |
+
output_path = f"processed_images/{filename}"
|
45 |
+
Image.open(image_path).save(output_path)
|
46 |
+
data.append({
|
47 |
+
'image_path': output_path,
|
48 |
+
'text': caption,
|
49 |
+
'label_file': os.path.basename(label_path)
|
50 |
+
})
|
51 |
+
except Exception as e:
|
52 |
+
print(f"Error processing image {image_path}: {e}")
|
53 |
+
|
54 |
+
print(f"\nProcessed {len(data)} total images successfully")
|
55 |
+
|
56 |
+
# Convert to dataframe and save as parquet
|
57 |
+
print("Converting to dataframe...")
|
58 |
+
df = pd.DataFrame(data)
|
59 |
+
print("Saving to parquet file...")
|
60 |
+
df.to_parquet("handwriting_dataset.parquet", index=False)
|
61 |
+
print("Dataset creation complete!")
|
62 |
+
|
63 |
+
if __name__ == "__main__":
|
64 |
+
create_dataset()
|
meta.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
We want to create huggingface dataset for image handwritten recognition
|
2 |
+
(1) Read the dataset from ./original/test/round31_best2019.label (It is encoded as Windows-784)
|
3 |
+
|
4 |
+
round31_best2019.label
|
5 |
+
r31-0001.png เป็นมนุษย์สุดประเสริฐเลิศคุณค่า กว่าบรรดาฝูงสัตว์เดรัจฉาน
|
6 |
+
r31-0002.png เป็นมนุษย์สุดประเสริฐเลิศคุณค่า กว่าบรรดาฝูงสัตว์เดรัจฉาน
|
7 |
+
|
8 |
+
(2) Load the image from folder that is the first 3 letters of filename e.g. r31-0001.png located at ./original/test/r31/r31-0001.png
|
9 |
+
(3) Make image and caption pair save as the parquets
|
original/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
original/test/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
original/test/.gitattributes
ADDED
The diff for this file is too large to render.
See raw diff
|
|
original/test/r31/r31-0001.png
ADDED
Git LFS Details
|
original/test/r31/r31-0002.png
ADDED
Git LFS Details
|
original/test/r31/r31-0003.png
ADDED
Git LFS Details
|
original/test/r31/r31-0004.png
ADDED
Git LFS Details
|
original/test/r31/r31-0005.png
ADDED
Git LFS Details
|
original/test/r31/r31-0006.png
ADDED
Git LFS Details
|
original/test/r31/r31-0007.png
ADDED
Git LFS Details
|
original/test/r31/r31-0008.png
ADDED
Git LFS Details
|
original/test/r31/r31-0009.png
ADDED
Git LFS Details
|
original/test/r31/r31-0010.png
ADDED
Git LFS Details
|
original/test/r31/r31-0011.png
ADDED
Git LFS Details
|
original/test/r31/r31-0012.png
ADDED
Git LFS Details
|
original/test/r31/r31-0013.png
ADDED
Git LFS Details
|
original/test/r31/r31-0014.png
ADDED
Git LFS Details
|
original/test/r31/r31-0015.png
ADDED
Git LFS Details
|
original/test/r31/r31-0016.png
ADDED
Git LFS Details
|
original/test/r31/r31-0017.png
ADDED
Git LFS Details
|
original/test/r31/r31-0018.png
ADDED
Git LFS Details
|
original/test/r31/r31-0019.png
ADDED
Git LFS Details
|
original/test/r31/r31-0020.png
ADDED
Git LFS Details
|
original/test/r31/r31-0021.png
ADDED
Git LFS Details
|
original/test/r31/r31-0022.png
ADDED
Git LFS Details
|
original/test/r31/r31-0023.png
ADDED
Git LFS Details
|
original/test/r31/r31-0024.png
ADDED
Git LFS Details
|
original/test/r31/r31-0025.png
ADDED
Git LFS Details
|
original/test/r31/r31-0026.png
ADDED
Git LFS Details
|
original/test/r31/r31-0027.png
ADDED
Git LFS Details
|
original/test/r31/r31-0028.png
ADDED
Git LFS Details
|
original/test/r31/r31-0029.png
ADDED
Git LFS Details
|
original/test/r31/r31-0030.png
ADDED
Git LFS Details
|
original/test/r31/r31-0031.png
ADDED
Git LFS Details
|
original/test/r31/r31-0032.png
ADDED
Git LFS Details
|
original/test/r31/r31-0033.png
ADDED
Git LFS Details
|
original/test/r31/r31-0034.png
ADDED
Git LFS Details
|
original/test/r31/r31-0035.png
ADDED
Git LFS Details
|
original/test/r31/r31-0036.png
ADDED
Git LFS Details
|
original/test/r31/r31-0037.png
ADDED
Git LFS Details
|
original/test/r31/r31-0038.png
ADDED
Git LFS Details
|
original/test/r31/r31-0039.png
ADDED
Git LFS Details
|
original/test/r31/r31-0040.png
ADDED
Git LFS Details
|
original/test/r31/r31-0041.png
ADDED
Git LFS Details
|
original/test/r31/r31-0042.png
ADDED
Git LFS Details
|
original/test/r31/r31-0043.png
ADDED
Git LFS Details
|
original/test/r31/r31-0044.png
ADDED
Git LFS Details
|
original/test/r31/r31-0045.png
ADDED
Git LFS Details
|