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()