Process finished with exit code -1073741819 (0xC0000005)

模型训练完毕,在win10系统下加载pb模型运行测试程序时,报错:

Process finished with exit code -1073741819 (0xC0000005)

因为我把整个测试图片都加载进来,和底库中的1000id特征进行对比,把batch size改为10,这个问题就解决了,又报另外的错误:

Process finished with exit code -1073740791 (0xC0000409)

后来发现是batch size 读取程序有问题,下面是改正后的代码:

# -*- coding: utf-8 -*-
import os
import argparse
import time
import tensorflow as tf
import cv2
from sklearn.preprocessing import normalize
import numpy as np
# 1:1000 test

class test_slim:
    def __init__(self, batch_size=1):
        self.yunce_path = r'F:\depth-face\test_all_id.tfrecords'
        self.ids_path = 'ids_1k.tfrecords'
        self.batch_size = batch_size

    def pre_process_orbbec(self, example_proto):# 读取整个测试集-> model
        features = {
            'id': tf.FixedLenFeature([], tf.int64),
            'label': tf.FixedLenFeature([], tf.int64),
            'color_raw': tf.FixedLenFeature([], tf.string),
        }
        features = tf.parse_single_example(example_proto, features)

        color = tf.image.decode_jpeg(features['color_raw'])
        color = tf.cast(color, tf.float32)
        #color = tf.image.crop_to_bounding_box(color, 0, 0, 56, 112)
        ir = color
        depth = color
        label = tf.cast(features['label'], tf.int64)
        # return color, ir, depth, label
        return color, label

    def get_orbbec_batch(self, batch_size): # 读取batch
        dataset = tf.data.TFRecordDataset(self.yunce_path)
        dataset = dataset.map(self.pre_process_orbbec)
        dataset = dataset.batch(batch_size)
        # dataset = dataset.apply(tf.contrib.data.batch_and_drop_remainder(batch_size))
        dataset = dataset.repeat(100)
        iterator = dataset.make_one_shot_iterator()
        next_element = iterator.get_next()

        return next_element


    def cacu_roc(self,threshold, dis_list, issame_list):
        predict_issame = np.less(dis_list, threshold).squeeze()
        tp = np.sum(np.logical_and(predict_issame, issame_list))
        fp = np.sum(np.logical_and(predict_issame, np.logical_not(issame_list)))
        tn = np.sum(np.logical_and(np.logical_not(predict_issame), np.logical_not(issame_list)))
        fn = np.sum(np.logical_and(np.logical_not(predict_issame), issame_list))
        tpr = 0 if (tp + fn == 0) else float(tp) / float(tp + fn)
        fpr = 0 if (fp + tn == 0) else float(fp) / float(fp + tn)
        acc = float(tp + tn) / len(dis_list)
        return acc, tpr, fpr


if __name__ == '__main__':
    embedding_1k = np.load(r'F:\depth-face\ids_se_112_embedding.npy')#加载1000id embedding
    #test_data = test_slim()
    print('length of embedding1k is:', len(embedding_1k))
    embedding_list = [] #特征列表
    test_data = test_slim(batch_size=1)#一次取一张图片
    threshold = 0.01
    pred_right = 0
    tp = 0
    tn = 0
    fp = 0
    fn = 0
    ids = list(np.arange(1000))
    data_test_batch = test_data.get_orbbec_batch(batch_size=1)
    print(data_test_batch)
    # 加载pb文件
    with tf.gfile.GFile(r'F:\depth-face\ckpt_resnet50_se\train_resnet50_se.pb', 'rb') as f:
        restored_graph_def = tf.GraphDef()
        restored_graph_def.ParseFromString(f.read())

    tf.import_graph_def(restored_graph_def,
                        input_map=None,
                        return_elements=None,
                        name='')
    graph = tf.get_default_graph()
    input_node = graph.get_tensor_by_name('input:0')
    output_node = graph.get_tensor_by_name('output:0')
    print('output_node:',output_node)
    #with tf.Session(config=tf.ConfigProto(allow_soft_place=True, gpu_options=tf.GPUOptions(allow_growth=True))) as sess:
    with tf.Session() as sess:
        for i in range(89298):  # 89298为测试图片的总数
            dis_list = []
            color, label = sess.run(data_test_batch)#读取图片与对应的label
            #print(color.shape)
            color = color[0]
            #print('color:',color)
            #print('label:',label)
            embedding = sess.run(output_node, feed_dict={input_node: [color]})
            embedding = normalize(embedding)#将特征进行归一化
            for index, em in enumerate(embedding_1k):#index就是对应图片特征的id
                diff = np.subtract(embedding, em)
                dis = np.sum(np.square(diff))
                dis = np.sqrt(dis)
                if index % 1000 == 0:
                    print(index)
                dis_list.append(dis)
            #print('length of dis_list is:', len(dis_list))
            if np.min(dis_list) <= threshold:#预测图片与底库id的特征足够接近
                min_val = np.min(dis_list)
                print(min_val)
                #pred_id = np.argmin(dis_list)
                pred_id = dis_list.index(min_val)
                print('pred_id', pred_id)
                if pred_id in ids:
                    tp = tp + 1
                else:
                    fp = fp + 1
            else:
                pred_id = np.argmin(dis_list)
                if pred_id in ids:
                    fn = fn + 1
                else:
                    tn = tn + 1
            '''if pred_id == label:
                pred_right = pred_right + 1'''
        tpr = 0 if (tp + fn == 0) else float(tp) / float(tp + fn)
        fpr = 0 if (fp + tn == 0) else float(fp) / float(fp + tn)
        acc = float(tp + tn) / len(dis_list)
        print('acc:', acc)
        print('tpr:', tpr)
        print('fpr:', fpr)




加更:后来又出现了这个错误,通过指定显卡解决了问题,参考:链接

import os 
os.environ["CUDA_VISIBLE_DEVICES"] = "2"

以上对我个人是有效的,造成这个错误的原因很多,需要慢慢排查。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一位不愿暴露自己的小可爱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值