kobkrit commited on
Commit
6ffeb43
1 Parent(s): 73e2dbb

Fix image content format

Browse files
convert.py CHANGED
@@ -22,6 +22,9 @@ def create_dataset():
22
  for i, label_path in enumerate(label_files):
23
  print(f"\nProcessing label file {i+1}/{len(label_files)}: {label_path}")
24
 
 
 
 
25
  # Read label file with Windows-874 encoding
26
  print("Reading label file...")
27
  with codecs.open(label_path, 'r', encoding='cp874') as f:
@@ -37,31 +40,29 @@ def create_dataset():
37
  # Get folder name from first 3 chars of filename
38
  folder = filename[:3]
39
  image_path = f"./original/test/{folder}/{filename}"
40
-
41
  # Load and verify image exists
42
  if os.path.exists(image_path):
43
  try:
44
  # Load image and convert to bytes
45
  img = Image.open(image_path)
46
  img_byte_arr = io.BytesIO()
47
- img.save(img_byte_arr, format=img.format)
48
- img_byte_arr = img_byte_arr.getvalue()
49
 
50
  data.append({
51
- 'image': img_byte_arr,
52
  'text': caption,
53
  'label_file': os.path.basename(label_path)
54
  })
55
  except Exception as e:
56
  print(f"Error processing image {image_path}: {e}")
57
-
58
  print(f"\nProcessed {len(data)} total images successfully")
59
 
60
  # Convert to dataframe and save as parquet
61
  print("Converting to dataframe...")
62
  df = pd.DataFrame(data)
63
  print("Saving to parquet file...")
64
- df.to_parquet("train.parquet", index=False)
65
  print("Dataset creation complete!")
66
 
67
  if __name__ == "__main__":
 
22
  for i, label_path in enumerate(label_files):
23
  print(f"\nProcessing label file {i+1}/{len(label_files)}: {label_path}")
24
 
25
+ if (i > 1):
26
+ break
27
+
28
  # Read label file with Windows-874 encoding
29
  print("Reading label file...")
30
  with codecs.open(label_path, 'r', encoding='cp874') as f:
 
40
  # Get folder name from first 3 chars of filename
41
  folder = filename[:3]
42
  image_path = f"./original/test/{folder}/{filename}"
 
43
  # Load and verify image exists
44
  if os.path.exists(image_path):
45
  try:
46
  # Load image and convert to bytes
47
  img = Image.open(image_path)
48
  img_byte_arr = io.BytesIO()
49
+ img.save(img_byte_arr, format='PNG') # Force PNG format
50
+ img_bytes = {"bytes":bytearray(img_byte_arr.getvalue())}
51
 
52
  data.append({
53
+ 'image': img_bytes, # Store as numpy array of bytes
54
  'text': caption,
55
  'label_file': os.path.basename(label_path)
56
  })
57
  except Exception as e:
58
  print(f"Error processing image {image_path}: {e}")
 
59
  print(f"\nProcessed {len(data)} total images successfully")
60
 
61
  # Convert to dataframe and save as parquet
62
  print("Converting to dataframe...")
63
  df = pd.DataFrame(data)
64
  print("Saving to parquet file...")
65
+ df.to_parquet("handwriting/train-00000-of-00001.parquet", index=False)
66
  print("Dataset creation complete!")
67
 
68
  if __name__ == "__main__":
handwriting/train-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:8a79cd9166706fcb38e259d5583c1422870723bf4a25012b793e0f052bec7ced
3
- size 280731300
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cca39500aada63e183962dee73ed77aef60ca0eb8dcc9055b27a5338090ca248
3
+ size 26044477