当前位置:网站首页>测试开发备忘
测试开发备忘
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
边栏推荐
- 使用SaltStack自动化部署LNMP
- 架构实战营第8模块作业
- SQL audit tool self introduction owls
- Method of win7 system anti ARP attack
- How to write a JMeter script common to the test team
- Fundamentals of software testing and development | practical development of several tools in testing and development
- VAE:变分自编码器的理解与实现
- JS modify table font and table border style
- 软件测试开发基础|测开中的几个工具开发实战
- RFs self study notes (II): theoretical measurement model - without clutter but with detection probability
猜你喜欢

Using Baidu easydl to realize chef hat recognition of bright kitchen and stove

Parity rearrangement of Bm14 linked list

Tikz draw Gantt chart in FJSP -trans necessary

After several twists and turns, how long can the TSDB C-bit of influxdb last?

【图像隐藏】基于DCT、DWT、LHA、LSB的数字图像信息隐藏系统含各类攻击和性能参数附matlab代码

Photoshop responsive web design tutorial
![[solved] ac86u ml revision firmware virtual memory creation failed, prompting that the USB disk reading and writing speed does not meet the requirements](/img/1c/6dbfcb5e6ade52d8cbfabcb34616a5.png)
[solved] ac86u ml revision firmware virtual memory creation failed, prompting that the USB disk reading and writing speed does not meet the requirements

架构实战营第8模块作业

Application of time series database in intelligent power consumption field

DevCon.exe 导出output至指定文件
随机推荐
RFs self study notes (III): clutter model - first determine the number with Poisson distribution, and then use uniform distribution as probability distribution
Powerbi time series analysis, prediction and visualization tutorial
pytest 自定义HOOK函数
SQL custom automatic calculation
R language text mining and natural language processing tutorial
C string to short[] method
Streamlit machine learning application development tutorial
SaltStack之数据系统
ES6's new data container map
Qt: one signal binds multiple slots
MES生产管理系统对设备的应用价值
BLDC 6步换相 simulink
Avoidance Adjusted Climbrate
顺序线性表——课上练
Efficiency comparison of JS array splicing push() concat() methods
Pytorch:快速求得NxN矩阵的主对角线(diagonal)元素与非对角线元素
CVPR21-无监督异常检测《CutPaste:Self-Supervised Learning for Anomaly Detection and Localization》
软件测试开发基础|测开中的几个工具开发实战
[filter tracking] target tracking based on EKF, TDOA and frequency difference positioning with matlab code
Bm11 list addition (II)