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:
|
3 |
-
size
|
|
|
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:
|
3 |
-
size
|
|
|
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:
|
3 |
-
size
|
|
|
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:
|
3 |
-
size
|
|
|
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:
|
3 |
-
size
|
|
|
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)
|