10/23/2023

comparing custom custom_vit_image_processor vs vit_image_processor of tranformers

 check custom image process is same with origin inner processing function in transformers.

.

pixel_values1 = self.feature_extractor(images=image, return_tensors="pt").pixel_values

# Convert numpy array to PyTorch tensor
pixel_values2 = self.custom_vit_image_processor(image)
pixel_values2 = torch.tensor(pixel_values2, dtype=torch.float32).unsqueeze(0) # Add batch dimension and ensure float32 type

# 1. Shape Check
assert pixel_values1.shape == pixel_values2.shape, "The tensors have different shapes
# 2. Absolute Difference
diff = torch.abs(pixel_values1 - pixel_values2)

# 3. Summarize Discrepancies www.marearts.com
mean_diff = torch.mean(diff).item()
max_diff = torch.max(diff).item()
min_diff = torch.min(diff).item()
print(f"Mean Absolute Difference: {mean_diff}")
print(f"Maximum Absolute Difference: {max_diff}")
print(f"Minimum Absolute Difference: {min_diff}")


# Additionally, if you want to see where the maximum difference occurs:
max_diff_position = torch.where(diff == max_diff)
print(f"Position of Maximum Difference: {max_diff_position}")

..


Thank you.

Hope to helpful.


No comments:

Post a Comment