2022-03-29 16:52:16.716216: W tensorflow/core/kernels/data/generator_dataset_op.cc:107] Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initialized. The process may be terminated.
[[{{node PyFunc}}]]
由于数据过大,所以有时候要将batch_size设置的小一点才能够跑得出来。
还有一种就是跑到一半的时候,会出现图片不对(跑卷积神经网络),因此需要删除图片。笔者在跑猫狗分类的任务时就遇到了这样的情况,将代码发如下,希望读者能够读一下,其实只要改路径就能够去找到删除的照片了。
import os
import shutil
import warnings
import cv2
import io
from PIL import Image
warnings.filterwarnings("error", category=UserWarning)
base_dir = './data/cats_and_dogs' #此处改路径
for r in os.listdir(base_dir):
if r == '.DS_Store': # 在这里我们在 .DS_Store 跳过,如果要是有需要的删除.DS_Store文件,可以进行微调
print(base_dir, r)
continue
for j in os.listdir(os.path.join('./data/cats_and_dogs', r)):
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(os.path.join('./data/cats_and_dogs/{}'.format(r), j)):
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)