GithubHelp home page GithubHelp logo

Comments (7)

huanghoujing avatar huanghoujing commented on June 21, 2024

多谢你的关注!
这个is_pos的第i行表示所有样本和第i个样本之间是否是同一个id,对角线上肯定是True,如果第j, k, l个样本和第i个样本同一个id,那么第i行的第j, k, l应该是Trueis_pos一般情况下不是对角阵。这个错误我没能一眼看出来是哪里的不兼容。

from alignedreid-re-production-pytorch.

chapmancpp avatar chapmancpp commented on June 21, 2024

N = dist_mat.size(0) #这是您N的定义
您之前定义了N的大小,为矩阵大小,
然而当队列中出现相同的ID的时候,即为非对角矩阵时,那么
is_pos = labels.expand(N, N).eq(labels.expand(N, N).t()) ,
dist_mat[is_pos]的维数就会不等于N。
那么,下面很多用N定义的就会报错了,比如下面这行:
dist_ap, relative_p_inds = torch.max(
dist_mat[is_pos_test].contiguous().view(N, -1), 1, keepdim=True)#报错

dist_mat[is_pos_test].contiguous()的维数不等于N,就不能用view(N,1).您看我理解的对吗,是不是我哪边理解错了。

from alignedreid-re-production-pytorch.

huanghoujing avatar huanghoujing commented on June 21, 2024

举个例子,labels[1, 2, 3, 4, 2, 1, 3, 4, 4, 2, 1, 3],也即4个id,每个id有3张图片,那么is_pos应该是(为了简化,下面的1表示True, 0表示False):

1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0
0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0
0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1
0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0
0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0
0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1
0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0
0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0
0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0
0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1

对角线都是1,每一行总共有3个1,所以dist_mat[is_pos].contiguous().view(N, -1)里边的-1就相当于3dist_mat[is_pos].contiguous().view(N, -1)的结果是一个12*3的数组。

我发现上面你的代码中好像有点问题,dist_ap, relative_p_inds = torch.max( dist_mat[is_pos_test].contiguous().view(N, -1), 1, keepdim=True)这里边is_pos_test不对吧,应该是is_pos

from alignedreid-re-production-pytorch.

chapmancpp avatar chapmancpp commented on June 21, 2024

后来发现是我对triplet loss的理解问题。哈哈,谢谢大佬。大佬在国外的吗?羡慕。

from alignedreid-re-production-pytorch.

huanghoujing avatar huanghoujing commented on June 21, 2024

大佬这个还是不敢当。。没在国外啊。。。

from alignedreid-re-production-pytorch.

Kang9779 avatar Kang9779 commented on June 21, 2024

后来发现是我对triplet loss的理解问题。哈哈,谢谢大佬。大佬在国外的吗?羡慕。

N = dist_mat.size(0) #这是您N的定义
您之前定义了N的大小,为矩阵大小,
然而当队列中出现相同的ID的时候,即为非对角矩阵时,那么
is_pos = labels.expand(N, N).eq(labels.expand(N, N).t()) ,
dist_mat[is_pos]的维数就会不等于N。
那么,下面很多用N定义的就会报错了,比如下面这行:
dist_ap, relative_p_inds = torch.max(
dist_mat[is_pos_test].contiguous().view(N, -1), 1, keepdim=True)#报错

dist_mat[is_pos_test].contiguous()的维数不等于N,就不能用view(N,1).您看我理解的对吗,是不是我哪边理解错了。

我也遇到了这个问题,你解决了吗?

from alignedreid-re-production-pytorch.

Kang9779 avatar Kang9779 commented on June 21, 2024

举个例子,labels[1, 2, 3, 4, 2, 1, 3, 4, 4, 2, 1, 3],也即4个id,每个id有3张图片,那么is_pos应该是(为了简化,下面的1表示True, 0表示False):

1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0
0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0
0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1
0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0
0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0
0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1
0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0
0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0
0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0
0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1

对角线都是1,每一行总共有3个1,所以dist_mat[is_pos].contiguous().view(N, -1)里边的-1就相当于3dist_mat[is_pos].contiguous().view(N, -1)的结果是一个12*3的数组。

我发现上面你的代码中好像有点问题,dist_ap, relative_p_inds = torch.max( dist_mat[is_pos_test].contiguous().view(N, -1), 1, keepdim=True)这里边is_pos_test不对吧,应该是is_pos

要是labels = [1, 2, 3, 4, 2, 1, 3, 4, 4, 2, 1, 1]这样的话,不就没法搞了吗

from alignedreid-re-production-pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.