Tagged: 代码

5,672  0

Fast RCNN: RoI Pooling 原理及代码

RoI Pooling 层 初始化参数 pooled_weight_ RoI池化层宽网格数(即论文中W=7) pooled_height_ RoI池化层高网格数(即论文中H=7) spatial_scale_ 从输入图像的坐标到特征图像坐标的缩放值 Forward函数流程 输入:(特征图data,位置信息rois) * Batch个 从Batch中取一张特征图datas的一个通道data,从此图对应的rois中取一个roi,得到(id,x,y,w,h) 缩放roi使其对应到特征图中位置(四舍五入为整数)得到(Rx,Ry,Rw,Rh) round(roi * spatial_scale_) 通过Rw,Rh得到每个bin的长宽BINw,BINh(四舍五入为整数) round(Rw / pooled_weight_) 遍历BIN中的特征值,将最大值作为输出,并记录此值对应在特征图的位置 示意图 Caffe代码 摘自 jiongnima //cpu前传函数 template <typename Dtype> void ROIPoolingLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { const Dtype* bottom_data = bottom[0][/latex]gt;cpu_data();//bottom_data表示共享卷积层输出的特征图 const Dtype* bottom_rois = bottom[1][/latex]gt;cpu_data();//bottom_rois表示rois的信息,一共5维,第一维表示rois在训练batch中的图片索引,后四维表示rois的坐标信息 // Number of ROIs int num_rois = bottom[1][/latex]gt;num();//roi的总数 int batch_size = bottom[0][/latex]gt;num();//batch_size表示一次训练中输入的图片数量,因为roi并不是都存在于同一张图片上 int top_count = top[0][/latex]gt;count();//top_count表示top[0]的全部容量(N*C*H*W) Dtype* top_data = top[0][/latex]gt;mutable_cpu_data();//使用top_data指针索引top[0] caffe_set(top_count, Dtype(-FLT_MAX), top_data);//初始化top_data(即top[0]),将其初始值(共top_count个)置为最小值(-FLT_MAX) int* argmax_data = max_idx_.mutable_cpu_data();//使用argmax_data指针索引max_idx_ caffe_set(top_count, -1, argmax_data);//初始化argmax_data(即max_idx_),将其初始值(共top_count个)置为-1 // For each ROI R = [batch_index x1 y1 x2 y2]: max pool over R (rois的五维数据的说明) for (int n =...

2,536  0

Numpy、Pandas语法小记

设置 pd.set_option(‘display.mpl_style’, ‘default’) # Make the graphs a bit prettier #option display.mpl_style providing a sleeker visual style for plots, based on [GH3075][1] pd.set_option(‘display.line_width’, 5000) pd.set_option(‘display.max_columns’, 60) DataFrame df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=[‘A’,’B’,’C’,’D’]) df = pd.read_csv(path_train, encoding="utf-8", header=0) df.to_csv(path,columns=[‘Pred’], index=True, header=True) df.info()#类型 df.describe()#统计 时间转换 data[‘TIME’] = pd.to_datetime(data[‘TIME’], unit=’s’) #将Unix毫秒数据转为datetime格式 data[‘TIME’].astype(‘<M8[ns]’) #转换列类型 data[‘HOUR’] = [i.hour for i in data["TIME"]] #从datetime中取小时 重命名列名 df.index.name = ‘Id’ #重命名索引列 df.columns = [‘Id’, ‘Pred’] #重命名所有列 df.rename(columns={‘Y’:’Pred’}, inplace = True) #重命名指定列 选取DataFrame信息 #取列 df[‘A’]#得到Series类型 df[[‘A’,’B’]]#得到DataFrame类型 #取行 df.loc[100],df.ix[100] #按index值取Series df.iloc[0] #按位置选Series df.loc[[100,101,102]],df.loc[100:103] df.iloc[[0,1,2]],df.iloc[0:3] #取值 df.loc[100][‘A’],df.loc[100,’A’]#float64 df.loc[100,[‘A’]],df.ix[100:102,[‘A’,’B’]]#Series/DataFrame df.iloc[0][‘A’]#取值 df.iloc[0:2][[‘A’,’B’]]#取值