|
|
import os |
|
|
import hashlib |
|
|
import datasets |
|
|
|
|
|
|
|
|
root_path = './Datasets/' |
|
|
data = datasets.load_dataset("allenai/pixmo-points", split="train", cache_dir=root_path) |
|
|
len_data = len(data) |
|
|
image_folder = os.path.join(root_path,"pixmo_images") |
|
|
|
|
|
|
|
|
for i,example in enumerate(data): |
|
|
print(i,len_data,f"{(i / len_data) * 100:.3f}%") |
|
|
|
|
|
image_hash = example["image_sha256"] |
|
|
image_path = os.path.join(image_folder, f"{image_hash}.jpg") |
|
|
|
|
|
if not os.path.exists(image_path): |
|
|
print('image does not exist, skip') |
|
|
continue |
|
|
|
|
|
with open(image_path, "rb") as img_file: |
|
|
image_bytes = img_file.read() |
|
|
file_hash = hashlib.sha256(image_bytes).hexdigest() |
|
|
print('hash matches') |
|
|
|
|
|
if file_hash != image_hash: |
|
|
os.remove(image_path) |
|
|
print('hash mismatch, delete') |
|
|
|
|
|
|