博文

目前显示的是 三月, 2019的博文

cmc计算

cmc计算 行人重识别中,计算cmc曲线代码的理解 假设我们已经通过网络得到query和gallery中每个行人的特征,并据此计算出对应的距离矩阵,为了方便,我们假设query和gallery中各有5个行人,因此得到的distmat大小为5*5。 distmat= [[0 1 2 3 4] [2 1 3 5 4] [4 0 6 3 5] [1 3 7 2 4] [0 3 4 1 5]] 对每一行从小到大排序,返回对应元素的位置, indices = np.argsort(distmat, axis=1) indices= [[0 1 2 3 4] [1 0 2 4 3] [1 3 0 4 2] [0 3 1 4 2] [0 3 1 2 4]] 理想的情况下,对应每一行,我们希望最小的出现在第一个,例如对于第一行,id=0,因此距离最小的index也应该是0;同理,对于第三行,id=2,希望最小的index=2出现在最前面的位置。matches要得到的是正确匹配的idx出现的位置。 matches = (g_pids[indices] == q_pids[:, np.newaxis]).astype(np.int32) orig_cmc = matches[q_idx][keep] orig_cmc = [1 0 0 0 0] [1 0 0 0 0] [0 0 0 0 1] [0 1 0 0 0] [0 0 0 0 1] 从orig_cmc我们已经可以看到,第一列中只出现两个1,因此rank-1就是2/5=0.4。前两列中出现3个1,rank-2就是3/5=0.6。

无需得到最佳epoch,计算rank-1

无需得到最佳epoch,计算rank-1 import os def get_best_rank(log_file): os.system('grep Results -A 6 '+log_file+' > get_old_result.txt') all_r1, all_r5, all_r10, all_r20 = [], [], [], [] with open('get_old_result.txt') as f: while True: line = f.readline() if 'Rank-1 ' in line: all_r1.append(float(line.split(': ')[-1].strip('%\n'))) elif 'Rank-5 ' in line: all_r5.append(float(line.split(': ')[-1].strip('%\n'))) elif 'Rank-10 ' in line: all_r10.append(float(line.split(': ')[-1].strip('%\n'))) elif 'Rank-20 ' in line: all_r20.append(float(line.split(': ')[-1].strip('%\n'))) if not line: break all_max = [0,0,0,0] while True: if all_r1 == []: break max_r...

计算rank1脚本

计算rank1脚本 s_r1=0 s_r5=0 s_r10=0 s_r20=0 echo "Sp_ID Rank-1 Rank-5 Rank-10 Rank-20" > te.txt function getdir(){ for element in `ls $1` do dir_or_file=$1"/"$element if [ -d $dir_or_file ] then best_rank1=$(grep rank-1 $dir_or_file"/log_train.txt") # grep the line: best rank-1 {} occured at epoch {} best_r1_value=${best_rank1:12:5} # get the rank-1 value, e.g, 90.00 best_epoch=${best_rank1:36:3} best_epoch_add=$(($best_epoch+1)) best_all_rank=$(grep "==> Epoch "$best_epoch -A 15 $dir_or_file"/log_train.txt" > temp.txt) best_r5_value=$(grep Rank-5 temp.txt) best_r10_value=$(grep Rank-10 temp.txt) best_r20_value=$(grep Rank-20 temp.txt) best_r5_value=${best_r5_value##*:} best_r10_value=${best_r10_value##*:} best_r20_value=${best_r20_value##*:} best_r5_value=${best_r5_value%*%} ...

服务器上的gedit配置

服务器上的gedit配置 用ssh连接服务器后使用gedit,在图形界面设置完成后,退出重启又是默认的设置,比如设置tab的宽度是4之后,退出gedit重启又变成默认的宽度8。 使用命令: gsettings list-recursively | grep -i gedit 可查看所有gedit的设置,现在假设我们需要显示行数,就输入以下命令 gsettings set org.gnome.gedit.preferences.editor display-line-numbers true 输入命令后如出现 Using the 'memory' GSettings backend. Your settings will not be saved or shared with other applications. 则需要在~/.bashrc文件中添加 export GIO_EXTRA_MODULES=/usr/lib/x86_64-linux-gnu/gio/modules/ 并重启终端 设置tab的宽度为4,替换tab为空格,自动缩进,自动保存 gsettings set org.gnome.gedit.preferences.editor tabs-size 4 gsettings set org.gnome.gedit.preferences.editor insert-spaces true gsettings set org.gnome.gedit.preferences.editor auto-indent true gsettings set org.gnome.gedit.preferences.editor auto-save true 若是安装了plugin tools,即可开启代码注释(ctrl + m),取消注释(ctrl + shift + m) gsettings set org.gnome.gedit.plugins active-plugins "['filebrowser', 'drawspaces', 'modelines', 'spell', 'time',...

np.concatenate()

np.concatenate() np.concatenate()的用法和torch.cat()的用法相同 qf.append(features) pids = pids.numpy().astype(np.int16) camids = camids.numpy().astype(np.int16) q_pids.append(pids) q_camids.append(camids) qf = torch.cat(qf) q_pids = np.asarray(np.concatenate(q_pids)) q_camids = np.asarray(np.concatenate(q_camids)) 其中q_pids包含的是numpy数组的列表,通过np.concatenate()可以直接转化成为列数组。如果先前不用pids = pids.numpy().astype(np.int16)来将pids转化为numpy数组,用torch.cat()也可以达到同样的效果。