import os
import cv2
import numpy as np
from tqdm import tqdm
# read txt file content to list
def ReadTxt_to_list(rootdir):
lines = []
with open(rootdir, 'r') as file_to_read:
while True:
line = file_to_read.readline()
if not line:
break
line = line.rstrip('\n')
lines.append(line)
return lines
def check_exist_nan(lstFile):
rt = os.path.split(lstFile)[0]
notExist = open(os.path.join(rt,'Lst_notExist.txt'),'w')
bad = open(os.path.join(rt,'Lst_bad.txt'),'w')
lines = ReadTxt_to_list(lstFile)
notNum = 0
badNum = 0
newLines = []
for line in tqdm(lines):
info_ = line.split('\t')
assert len(info_) == 3
_, filePth, idNum = info_
if not os.path.exists(filePth):
print('Not exist:', line)
notExist.write(line+'\n')
notNum += 1
else:
img = cv2.imread(filePth)
try:
if np.any(np.isnan(img)) or not np.all(np.isfinite(img)):
print('Nan/Inf:', line)
badNum += 1
bad.write(line + '\n')
else:
newLines.append(line)
except:
print('Error:', line)
badNum += 1
bad.write(line + '\terror\n')
print('Not exist', notNum)
print('Bad', badNum)
if len(lines) != len(newLines):
newLst = open(os.path.join(rt,'Lst_new.txt'), 'w')
for line in newLines:
newLst.write(line+'\n')
newLst.close()
notExist.close()
bad.close()
if __name__ == '__main__':
imgLst = '/home/img.lst'
check_exist_nan(imgLst)
Read More:
- When using quartus for function simulation, “testbench” appears_ vector_ input_ The solution of “file option does not exist”
- SAP Migo 101 receives the work order and reports an error – check table tfbefu_ CR entry 10 does not exist – Countermeasures
- [Solved] caffe Error: Check failed: cv_img.data Could not load
- Maven compilation error: package does not exist jar package does not exist
- In the next two years, how do data analysts hang up highly educated engineers? be convinced!
- Solve the problem that data cannot be input in idea console
- dfs.namenode.name . dir and dfs.datanode.data .dir dfs.name.dir And dfs.data.dir What do you mean
- “Typeerror: invalid dimensions for image data” in Matplotlib drawing imshow() function
- [Solved] Failed to set attribute: Invalid input data or parameter
- U disk installation Linux system could not boot, / dev / root does not exist and the identified hard disk space is not available
- Solution of “do not use ‘new’ for side effects” for eslint verification of Vue project
- Error: command error out with exit status 1: Python setup.py egg_ inf
- Ant Design upload listtype = “picture card” realizes multi image upload and click preview image encapsulation
- VTK cultivation 26: basic operation of image_ Three dimensional image slice extraction
- May cause (ora-01006: binding variable does not exist) problems
- Ueditor paste word image and upload image file automatically
- package xxx does not exist cannot find symbol
- Error:Cannot start process,the working directory does not exist
- [MySQL] [serialize] [error record] after modifying data, no data will be returned (in fact, MySQL does not support it)
- DNS name does not exist