关于玩神经网络进行跑数据的坑

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)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值