Skip to content

Instantly share code, notes, and snippets.

View hewumars's full-sized avatar

Mars hewumars

View GitHub Profile
void savebmp(char *name,HI_U8 *buffer,int w,int h) {
FILE *f=fopen(name,"wb");
if(!f) {
printf("Error writing image to disk.\n");
return;
}
unsigned int size=w*h*3+54;
HI_U8 header[54]={'B','M',size&255,(size>>8)&255,(size>>16)&255,size>>24,0,
0,0,0,54,0,0,0,40,0,0,0,w&255,w>>8,0,0,h&255,h>>8,0,0,1,0,24,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
import os, sys
import argparse
def read_jpg_path_list(file_dir):
L=[]
fp = open(os.path.join(file_dir,'YoloTestSettrain.txt'),'w')
for root,dirs,files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == '.jpg':
L.append(os.path.join(root,file))
1.逐行扫描图像,把每一行连续的非零目标像素组成一个序列称为一个块(block),并加下它的起点start、它的终点end以及它所在的行号。
void fillBlockVectors(const Mat& img,Lanes& lanes){
for(int i=0; i < img.rows; ++i){
const uchar* rowData = img.ptr<uchar>(i);
if(rowData[0] != 0){
lanes.NumOfBlocks++;
lanes.stBlock.push_back(0);
lanes.rowBlock.push_back(i);
lanes.lane_type.push_back(rowData[0]);
}
@hewumars
hewumars / align.c
Created March 6, 2019 09:02
16Byte和32Byte ALIGN对齐
#define ALIGN_16 16
#define ALIGN_32 32
#define HW_ALIGN_16(u32Num) ((u32Num+ALIGN_16-1)/ALIGN_16*ALIGN_16)
#define HW_ALIGN_32(u32Num) ((u32Num+ALIGN_32-1)/ALIGN_32*ALIGN_32)
@hewumars
hewumars / index.md
Last active April 10, 2019 09:41
图像矩阵维度索引,变换,permute

四维索引: Mat[((b*channels+c)*height+h)*width+w] Mat[B*channels*height*width+C*height*width+H*width+W]

要变换维度时,只有调换for循环位置到不同的循环层,例如yolo里面访问网格对应通道,代码如下 例如CHW-->HWC

//permute
        u32Offset = 0;
 ps32InputBlob = pps32InputData[i];
@hewumars
hewumars / Tops.md
Last active February 12, 2020 04:49
1.卷积和全连接层计算量FLOPs 2.带宽计算 3.峰值计算能力

GPU设备的单精度计算能力的理论峰值计算公式: 单精度计算能力的峰值 = 单核单周期计算次数 × 处理核个数 × 主频

以GTX680为例,   单核一个时钟周期单精度计算次数为两次,处理核个数 为1536, 主频为1006MHZ,那他的计算能力的峰值P 为
P = 2 × 1536 × 1006MHZ = 3.09TFLOPS
这里1MHZ = 1000000HZ, 1T为1兆,也就是说,GTX680每秒可以进行超过3兆次的单精度运算。
@hewumars
hewumars / readme.md
Last active January 6, 2020 03:02
结合Pruning Convolutional Neural Networks for Resource Efficient Inference 论文和YOLOv2在PyTorch上进行通道裁剪

实验结果

测试平台:GPU1070

网络:yolov3 类别 原始 裁剪 优化率
(384*352) 行人(Recall) 87.61 86.08
(Precision) 80.64 78.55
车辆 93.69 94.01
77.64 77.25
@hewumars
hewumars / readDir.c
Created March 8, 2019 01:13
readDir读取目录下的图片,保存到vector<string>中 支持jpg格式,其他需要修改代码
#include "dirent.h"
int readDir(char *basePath, vector<string> &filelist)
{
DIR *dir;
struct dirent *ptr;
char base[1000];
if ((dir = opendir(basePath)) == NULL)
{
printf("readDir:Open dir error...\n");
@hewumars
hewumars / self-attention.py
Last active March 11, 2019 01:54
Self-Attention GAN 中的 self-attention 机制 : self attention 看成是 feature map 和它自身的转置相乘,让任意两个位置的像素直接发生关系,这样就可以学习到任意两个像素之间的依赖关系,从而得到全局特征了。
classSelf_Attn(nn.Module):
""" Self attention Layer"""
def__init__(self,in_dim,activation):
super(Self_Attn,self).__init__()
self.chanel_in = in_dim
@hewumars
hewumars / cv_utils.cpp
Last active May 15, 2019 02:58
将blob转成Mat,然后保存成jpg
#include "opencv2/opencv.hpp"
#include "hi_ive.h"
static HI_VOID readChn(cv::Mat& dstMat, const HI_U8* pu8Data, HI_U8 u8Chn, HI_U32 u32Width, HI_U32 u32Height, HI_U32 u32Stride)
{
HI_U32 w, h;
for (w = 0; w < u32Width; w++)
{
for (h = 0; h < u32Height; h++)
{