when using the caffe training algorithm to classify the model, during the training, it was suggested that the failure to read the pictures caused interruption, so I wrote a script to delete the failed pictures in advance. The script is as follows:
import os
import shutil
import warnings
import cv2
import io
from PIL import Image
warnings.filterwarnings("error", category=UserWarning)
base_dir = "/data/chw/images"
i = 0
def is_read_successfully(file):
try:
imgFile = Image.open(file)
return True
except Exception:
return False
for parent, dirs, files in os.walk(base_dir):
for file in files:
if not is_read_successfully(os.path.join(parent, file)):
print(os.path.join(parent, file))
#os.remove(os.path.join(parent, file)) #真正使用时,这一行要放开,自己一般习惯先跑一遍,没有错误了再删除,防止删错。
i = i + 1
print(i)
p>
div>
Read More:
- Image proxy settings Flash + JavaScript
- Wechat applet background image error
- Keyerror occurred when openpyxl copied some excel with pictures:. MPO‘
- Converting PDF file to JPG image in Ubuntu
- Opencv detection yolov4 target detection video stream error
- Get picture captcha with Python + Chrome
- Image input data check: Nan inf and do not exist
- Error response from daemon: Conflict: unable to delete 8598c91556dc (must be forced)
- Visionox shows app development record
- Typeerror in Python: ‘nonetype’ object is not Iterable
- python3 request module https certificate verify failed error
- Simple Python crawler exercise: News crawling on sohu.com
- How to import Python from relative path
- Python conversion hex to string, high and low data processing
- Docker delete error response from daemon: Conflict: unable to delete xxxxx solution
- [Python] error reported when reading DICOM file pydicom.errors.invaliddicomerror
- The usage details of SVM
- Docker error response from daemon: Conflict: unable to deletexxxxx
- [HTML] Python extracts HTML text to TXT