当前位置:网站首页>测试开发备忘
测试开发备忘
2022-07-28 17:29:00 【weixin_42849849】
备忘
SHELL脚本
#!/bin/bash
#==========================================
#过滤灰度图和彩色图
for img in Image50K/*.JPEG ; do
c=`file $img | awk '{print $NF}'`
if [ $c == "1" ];then
echo $img
cp $img Image50K.gray/.
else
cp $img Image50K.color/.
fi
done
#==========================================
#提取一定数量的图片到指定路径,网络测试量化使用
i=0
n=2000
mkdir -p img$n
for img in Image50K.color/*.JPEG;do
cp $img img$n/.
i=$(($i+1))
[ $i -gt $n ] && break
done
#==========================================
#遍历列表
base_list=`cat <<EOF "./Classify/model/MobileNet-v1/mobilenet_merge_bn" "./Classify/model/MobileNet-v2/mobilenet-v2" "./Classify/model/Inception-v1/inception_v1_merge_bn" "./Classify/model/DenseNet121/densenet-121" "./Classify/model/ResNet50/ResNet50_train_val_merge_bn" "./Classify/model/SENet/se-resnet50_merge_bn" "./Classify/model/VGG16/VGG16_train_val" EOF `
for base_path in $base_list;do
echo $base_path
done
#===============================================================================
#判断列表里的第一个是否是文件,把是文件的提取出来
awk '{if(system("test -f " $1)==0) print $0}' <list_val.txt >list_val_color.txt
#===============================================================================
#随机提取n行
shuf list_val.txt | head -n 100
#================================================================================
base_list=`cat <<EOF ./Classify/model/MobileNet-v2/mobilenet-v2 ./Classify/model/MobileNet-v1/mobilenet_merge_bn ./Classify/model/DenseNet121/densenet-121 ./Classify/model/Inception-v1/inception_v1_merge_bn ./Classify/model/SqueezeNet_V1.1/squeezenet_train_val ./Classify/model/VGG16/VGG16_train_val ./Classify/model/SENet/se-resnet50_merge_bn ./Classify/model/ResNet50/ResNet50_train_val_merge_bn EOF `
for base_path in $base_list;do
proto=${base_path}.prototxt
model=${base_path}.caffemodel
logfile=`basename ${
base_path}.log`
echo $logfile
./caffe_predict.py ${proto} ${model} ${logfile} &> predict.log
tr -d "\[\]," <$logfile >${logfile}.1
mv ${logfile}.1 ${logfile}
./readlog.py ${logfile}
done
Python脚本
#=====================================================================
# 分析日志文件,计算top10
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import re
import sys,os
import numpy as np
counts=np.zeros([11],dtype=float)
def search(topk):
label=topk[-1]
pos=0
while True:
if topk[pos]==label:
return pos
pos=pos+1
logfile=sys.argv[1]
with open(logfile,'r') as f:
for line in f.readlines():
line.strip()
topk=[int(i) for i in line.split()]
pos=search(topk)
counts[pos]=counts[pos]+1
print(logfile,": counts",counts)
print(logfile," topk acc: ", np.cumsum(counts)/np.sum(counts))
#=======================================================================
#判断image是1通道,比较慢
#!/usr/bin/env python3
from PIL import Image
import sys,os
img=Image.open(sys.argv[1])
if len(img.split())==1:
print(sys.argv[1])
#========================================================================
#caffe_predict.py, 测试caffe模型
#!/usr/bin/env python3
import sys
import numpy as np
import cv2
import caffe
import time
from preprocess import *
# select GPU to predict
caffe.set_mode_gpu()
caffe.set_device(0)
#模型对应的前处理参数字典
transform_params={
\
'se-resnet50_merge_bn.log':(225,0.0170000009239,103.940002441,116.779998779,123.680000305), \
'mobilenet-v2.log':(224,0.017,103.94,116.78,123.68), \
'mobilenet_merge_bn.log':(224,0.0170000009239,103.940002441,116.779998779,123.680000305), \
'densenet-121.log':(224,0.017,103.94,116.78,123.68), \
'inception_v1_merge_bn.log':(224,1.0,128.0,128.0,128.0), \
'squeezenet_train_val.log':(227,1.0,103.939,116.779,123.68), \
'VGG16_train_val.log':(224,1.0,103.939,116.779,123.68), \
'ResNet50_train_val_merge_bn.log':(224,1.0,103.939,116.779,123.68), \
}
test_data_path = './caffe.dir//ILSVRC2012_val/'
model_file=sys.argv[1]
pretrained=sys.argv[2]
log_file=sys.argv[3]
transform=transform_params[log_file]
print(transform)
net = caffe.Net(model_file, pretrained, caffe.TEST)
crop_size=transform[0]
scale=transform[1]
mean=transform[2:]
f = open(test_data_path + "list_val.txt")
right = 0
i = 0
with open(log_file,'w') as fh:
#for line in f.readlines()[:500]:
for line in f.readlines():
line = line.strip().split(" ")
filename = line[0]
label =line[1]
image_path = test_data_path + filename
img = cv2.imread(image_path)
imgresize = resize(img, 256)
imgcrop=center_crop(imgresize,crop_size)
imgcrop = imgcrop.astype(np.float64)
stdvalue = 1 / scale # The std value is in the prototxt
std = (stdvalue, stdvalue, stdvalue)
imgcrop -= mean
imgcrop/=std
imgcrop = imgcrop.astype(np.float64)
#HWC->CHW
net.blobs['data'].data[...] = imgcrop.transpose((2, 0, 1))
start = time.time()
out = net.forward() # output
end = time.time()
running_time = end - start
print("filename:",filename)
output_prob = out['prob'][0]
print('predicted class is:', output_prob.argmax())
top_k = net.blobs['prob'].data[0].flatten().argsort()[-1:-11:-1]
ll=top_k.tolist()
ll.append(int(label))
print(ll)
fh.write(str(ll)+'\n')
print('time cost : %.5f s' % running_time)
Python调用so动态库
#include<cstdio>
#include<string>
#include<iostream>
/*********compile&link***********************/
/* g++ -c -Wall -Werror -fpic t.cpp g++ -shared -o libtest.so t.o */
/******Python************/
/* from ctypes import * soo=cdll.LoadLibrary("./libtest.so") func=soo._Z4funcPKcS0_i func(b'hello',b'world',4) */
//using namespace std;
int
func(const char *str1, const char *str2, int n)
{
printf("string_1: %s\n",str1);
//cout<<"string_1:"<<str1<<endl;
printf("string_2: %s\n",str2);
printf("n=%d\n",n);
return 1;
}
系统配置相关
#添加NFS共享盘,编辑修改/etc/fstab
#添加一行: x.x.x.x:/data /data nfs defaults 0 0
#可能需要安装mount.nfs
apt search mount.nfs
sudo apt install mount.nfs
#加载nfs共享盘
sudo mount -a
#下载deb包
apt-get download xxx.deb
#将deb包展开到指定路径
dpkg -X xxx.deb ./path
#添加动态库目录
#编辑/etc/ld.so.conf.d/slurm.conf
#刷新ld caches
ldconfig
#添加节点名字
echo "192.168.11.75 worker02" >>/etc/hosts
#显示节点硬件资源信息
slurmd -C
#drain状态处理,控制节点上操作
sudo scontrol update NodeName=worker02 State=DOWN Reason=hung_completing
sudo scontrol update NodeName=worker02 State=RESUME
#运行slurmd,调试信息
sudo `which slurmd` -D -vvvv
#调试ssh
ssh -vvv [email protected]
{
ssh -vvv [email protected];} 2>1.log
边栏推荐
- Learn from Li Mu in depth -softmax return
- 关于白盒测试,这些技巧你得游刃有余~
- [data analysis] realize SVDD decision boundary visualization based on MATLAB
- R language text mining and natural language processing tutorial
- VAE:变分自编码器的理解与实现
- How to use Qianqian listening sound effect plug-in (fierce Classic)
- Application of time series database in intelligent power consumption field
- Pointer learning of C language -- the consolidation of pointer knowledge and the relationship with functions, arrays and structures
- 当CNN遇见Transformer《CMT:Convolutional Neural Networks Meet Vision Transformers》
- 机器学习 --- 模型评估、选择与验证
猜你喜欢

6-20漏洞利用-proftpd测试

Fantasy 5 (ue5) game engine complete course 2022

关于ASM冗余问题

Share several coding code receiving verification code platforms, which will be updated in February 2022

Pytest custom hook function

Photoshop responsive web design tutorial
![[image hiding] digital image information hiding system based on DCT, DWT, LHA, LSB, including various attacks and performance parameters, with matlab code](/img/a4/5c5a90508e2f9c6b4f8e234bdfdc9e.png)
[image hiding] digital image information hiding system based on DCT, DWT, LHA, LSB, including various attacks and performance parameters, with matlab code

FTM module of K60: configure motor, encoder and steering gear

当CNN遇见Transformer《CMT:Convolutional Neural Networks Meet Vision Transformers》

From Bayesian filter to Kalman filter (zero)
随机推荐
剑指 Offer II 109. 开密码锁
Web 3.0 development learning path
用于异常检测的Transformer - InTra《Inpainting Transformer for Anomaly Detection》
Bm11 list addition (II)
RFs self study notes (4): actual measurement model - the mixture of OK and CK, and then calculate the likelihood probability
Application of time series database in Hydropower Station
SQL审核工具自荐Owls
Wechat solves the problem of long press selected style
Efficiency comparison of JS array splicing push() concat() methods
Libgdx learning road 02: draw game map with tiled
顺序线性表——课上练
Share several coding code receiving verification code platforms, which will be updated in February 2022
Lookup - lookup of sequential table and ordered table
From Bayesian filter to Kalman filter (2)
SRS4.0安装步骤
BM16 删除有序链表中重复的元素-II
Fundamentals of software testing and development | practical development of several tools in testing and development
Parity rearrangement of Bm14 linked list
From Bayesian filter to Kalman filter (zero)
VAE:变分自编码器的理解与实现