quentintaranpino commited on
Commit
0f9b30b
·
1 Parent(s): 8f93332

delete corrupt images. add test.py for testing

Browse files
data/train-00000-of-00005.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:a4f37108ea5c4140e86535e82fc7cf3e1212432dc880fa3b528515bf6a8a851f
3
- size 395775543
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:39c1105fb7c66746222256a1322f63599c5d044f4eaaef6e622d1092f7858b8f
3
+ size 550878063
data/train-00001-of-00005.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:246235337ae5b6504f907b33eea2eabf8b1349881414cba77d68bbd69377299b
3
- size 835997138
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:33794a73660868a2c713490feb7f5d82750ee8a84df74733666bff1df5fdf4f3
3
+ size 835192352
data/train-00002-of-00005.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c33be94e197654cd3f02d1edeaa2966075ae863961f80d01517277bb7fac839f
3
- size 1109849995
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e2b5e3814167f04b2ec6a78d1fd53680ff87b843c8d6a603429e78862eca173e
3
+ size 1110002638
data/train-00003-of-00005.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1d1f4a22b563a13d22a3d6892f67210ccc1b602ec33a4b15ab0cfaa2718b4525
3
- size 2687590855
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ff47568eb179bdb4b834f5936515b766625822a3f551e60863bd2d146d3c02a7
3
+ size 2688826273
data/train-00004-of-00005.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5ff4d0bbe8673e90818c5381b20c0a11b731401d7699c54cb72eb8b2808b902f
3
- size 444771295
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8485eaa9538de32345282c4e8f7354f6da436ec795de2ddb6767255ca78c9f4
3
+ size 444671011
test.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pyarrow.parquet as pq
2
+ import pyarrow as pa
3
+ from PIL import Image
4
+ import io
5
+ import pandas as pd
6
+
7
+ def is_image_corrupt(image_dict):
8
+ try:
9
+ image_bytes = image_dict['bytes']
10
+ image = Image.open(io.BytesIO(image_bytes))
11
+ image.verify()
12
+ return False
13
+ except (IOError, SyntaxError, KeyError) as e:
14
+ return True
15
+
16
+ def process_parquet_file(file_path, output_file_path):
17
+ table = pq.read_table(file_path)
18
+
19
+ df = table.to_pandas()
20
+
21
+ image_column = 'image'
22
+
23
+ clean_indices = []
24
+ corrupt_indices = []
25
+
26
+ for i, image_dict in enumerate(df[image_column]):
27
+ if is_image_corrupt(image_dict):
28
+ corrupt_indices.append(i)
29
+ else:
30
+ clean_indices.append(i)
31
+
32
+ clean_df = df.iloc[clean_indices]
33
+
34
+ clean_table = pa.Table.from_pandas(clean_df)
35
+
36
+ pq.write_table(clean_table, output_file_path)
37
+
38
+ print(f"File {file_path}: {len(corrupt_indices)} corrupt images were removed.")
39
+
40
+ for i in range(5):
41
+ input_file_path = f'data/train-0000{i}-of-00005.parquet'
42
+ output_file_path = f'data/train-0000{i}-of-00005.parquet'
43
+ process_parquet_file(input_file_path, output_file_path)