当前位置:网站首页>测试开发备忘
测试开发备忘
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
边栏推荐
- 2022年中总结
- Application of time series database in Hydropower Station
- Doxygen文档生成工具
- Solve the critical path in FJSP - with Matlab source code
- BLDC 6-step commutation simulink
- SaltStack之salt-ssh
- The ever-changing pointer ----- C language
- JS modify table font and table border style
- [machine learning] support vector machine classification
- More loading in applets (i.e. list paging)
猜你喜欢

Photoshop responsive web design tutorial

DevCon. Exe export output to the specified file

BLDC 6-step commutation simulink

Application of time series database in bridge monitoring field

VAE:变分自编码器的理解与实现

C language (high-level) character function and string function + Exercise

Prometheus部署

Nips18(AD) - 利用几何增广的无监督异常检测《Deep Anomaly Detection Using Geometric Transformations》

ACM warm-up exercise 3 in 2022 summer vacation (detailed)

Application of time series database in cigarette factory
随机推荐
[filter tracking] target tracking based on EKF, TDOA and frequency difference positioning with matlab code
Adobe XD web design tutorial
DevCon.exe 导出output至指定文件
Ardupilot software in the loop simulation and online debugging
剑指 Offer II 109. 开密码锁
pytest 自定义HOOK函数
BLDC 6-step commutation simulink
Bm11 list addition (II)
Pytest custom hook function
Wechat official account custom sharing and updateappmessagesharedata are all successful. Why is it a link that is shared?
[image hiding] digital image information hiding system based on DCT, DWT, LHA, LSB, including various attacks and performance parameters, with matlab code
Application of time series database in bridge monitoring field
BM16 删除有序链表中重复的元素-II
How to write a JMeter script common to the test team
[machine learning] support vector machine classification
Cv5200 wireless WiFi communication module, wireless video image transmission, real-time wireless communication technology
Fantasy 5 (ue5) game engine complete course 2022
Sudo rosdep init error: cannot download default
机器学习 --- 模型评估、选择与验证
Lookup - lookup of sequential table and ordered table