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:
- Implementation of screen cleaning in Python idle
- The python version output from the command line is inconsistent with the python version in the current CONDA environment
- Simple Python crawler exercise: News crawling on sohu.com
- Lua — using remove to delete table data
- Failed cleaning build dir for SciPy
- Solution to unbalanced load of multiple cards (GPU’s 0 card is too high) in Python model training (simple and effective)
- Docker delete error response from daemon: Conflict: unable to delete xxxxx solution
- MySQL will delete the data minutes before the current time
- To the brothers who encountered simple bind failed 192.168.1.×××: 636
- [Solved] Es delete all the data in the index without deleting the index structure, including curl deletion
- Python conversion hex to string, high and low data processing
- After changing tomcat, the previous images cannot be displayed. All 404,
- New version of grafana add data source error!
- [Solved] CAP_IMAGES: can‘t find starting number (in the name of file)
- Python export data (CSV format)
- Record the location and cleaning of chrome junk files under appdata of Disk C
- Opencv’s imread() function returns null when reading images
- conda install failed: conda.core.subdir_ data.Response304ContentUnchanged Python cannot be installed
- Bindtextureimage: cleaning GL error: 0x502 during Android opengles2.0 hard decoding
- Coursera Using python to access Web data quiz 4