去除4通道图像:
import cv2
import os
import shutil
folder_path = R'F:\bounding_box_test\bounding_box_train' # 更改为存储图片文件夹的路径
image_files = os.listdir(folder_path)
count = 0
for file_name in image_files:
if file_name.endswith('.jpg') or file_name.endswith('.png'): # 可根据文件扩展名进行调整
image_path = os.path.join(folder_path, file_name)
# print(file_name)
image = cv2.imread(image_path, cv2.IMREAD_UNCHANGED)
try:
a = image.shape
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
height, width, channels = image.shape
except:
os.remove(image_path)
print("Remove: " + image_path)
count +=1
if channels != 3:
os.remove(image_path)
print(file_name)
cv2.waitKey(0)
print(count)
cv2.destroyAllWindows()
删除损坏的图片 移出4通道图像
Original Traceback (most recent call last):
File "/home/sunyingli/miniconda3/envs/myv5/lib/python3.9/site-packages/torch/utils/data/_utils/worker.py", line 302, in _worker_loop
data = fetcher.fetch(index)
File "/home/sunyingli/miniconda3/envs/myv5/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch
return self.collate_fn(data)
File "/home/sunyingli/fast-reid/fastreid/data/build.py", line 187, in fast_batch_collator
return {key: fast_batch_collator([d[key] for d in batched_inputs]) for key in elem}
File "/home/sunyingli/fast-reid/fastreid/data/build.py", line 187, in <dictcomp>
return {key: fast_batch_collator([d[key] for d in batched_inputs]) for key in elem}
File "/home/sunyingli/fast-reid/fastreid/data/build.py", line 183, in fast_batch_collator
out[i] += tensor
RuntimeError: The size of tensor a (3) must match the size of tensor b (4) at non-singleton dimension 0