人脸模糊判断 属性网络

F:\project\cls\SLS_celian_alone_o

推理示例:

demo_3x6.py
# -*- coding: utf-8 -*-
from __future__ import print_function, division
import argparse
import csv
import datetime
import os

import pandas as pd
import cv2
import torch
import numpy as np
import torch.nn.functional as m_func


import time

# from call_cmd import onnx2mnn, mnn_encode
from pelee_6_3 import Pelee_pre_6_3

def val_face():

    list_path = r'B:\data\landmark_face\mask3\mask3\rgb\mask_train/'
    # list_path = r'D:\data\mask\mask3\rgb\mask_test'

    list_path=list_path[:-1]+list_path[-1].replace("/","")

    label_file = list_path+"/label.csv"
    save_file = list_path + "/result.csv"

    # cls_1=["mask","glass_sung/glass_normal","hand","else","blur","side", "is_train"]
    cls_1=["mask","glass_sung/glass_normal","hand","else","blur","side", "is_train","lock"]
    cls_len=len(cls_1)-2
    for tmp_cls in range(cls_len):
        cls_1.append(cls_1[tmp_cls]+"_pred")
    for tmp_cls in range(cls_len):
        cls_1.append(cls_1[tmp_cls] + "_score")
    if not os.path.isfile(save_file):
        with open(save_file, 'w', encoding='utf-8') as f:
            csv_writer = csv.writer(f)
            file_head = ['img_path']
            file_head.extend(cls_1)
            csv_writer.writerow(file_head)

    df_result = pd.read_csv(save_file)

    # model = Pelee_pre_6_3(model_path="./models/pelee_3_6/0.9791_0.9960_0.9544_0.9864_0.9566_0.9904_0.9906_86.pth.pth", num_classes=6)
    model = Pelee_pre_6_3(model_path=r"F:\project\cls\SLS_celian_alone_o\train_3_6\models\Pelee_cls_jz\0.9848_0.9973_0.9697_0.9890_0.9665_0.9935_0.9928_93.pth", num_classes=6)
    err_count = 0
    ok_count = 0
    score_small = 0

    df_train = pd.read_csv(label_file)

    for index, row in df_train.iterrows():
        img_path = row["img_path"]

        if not os.path.exists(list_path + img_path):
            continue
        img = cv2.imdecode(np.fromfile(list_path+img_path, dtype=np.uint8), 1)
        if img is None:
            continue

        begin = time.time()
        cls, score,output_o= model.get_cls([img])

        if not np.array_equal(row.values[1:(6+1)], cls[0]):
        # if not row.values[1:-1] == cls[0]:
            df_value=[img_path]
            df_value.extend(np.hstack((row.values[1:],cls[0],score[0])).tolist())
            df_result.loc[len(df_result) + 1] =df_value
            err_count+=1
            print(ok_count, err_count, score_small, img_path)
            df_result.to_csv(save_file, index=False)
        else:
            if min(score[0])<0.7:
                df_value = [img_path]
                df_value.extend(np.hstack((row.values[1:], cls[0],score[0])).tolist())
                df_result.loc[len(df_result) + 1] = df_value
                score_small += 1
                print(ok_count,err_count, score_small, img_path)
                df_result.to_csv(save_file, index=False)
            else:
                ok_count+=1
                print(ok_count, err_count, score_small, img_path)


if __name__ == "__main__":
    # exec_face()
    val_face()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

AI算法网奇

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

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

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

打赏作者

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

抵扣说明:

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

余额充值