Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract.py报错 #31

Open
vk-rrr opened this issue Oct 31, 2024 · 9 comments
Open

extract.py报错 #31

vk-rrr opened this issue Oct 31, 2024 · 9 comments

Comments

@vk-rrr
Copy link

vk-rrr commented Oct 31, 2024

运行extract.py报错
Traceback (most recent call last):
File "/home/hzh/Github/LLCM-main/DEEN/extract.py", line 268, in
query_feat_pool, query_feat_fc = extract_query_feat(query_loader)
File "/home/hzh/Github/LLCM-main/DEEN/extract.py", line 138, in extract_query_feat
query_feat_pool[ptr:ptr + batch_num, :] = feat_pool.detach().cpu().numpy()
ValueError: could not broadcast input array from shape (192,2048) into shape (64,2048)

把通道维度连接成一个特征,但是可视化的图不对,请问可以给出符合DEEN的extract.py详细代码吗?

def extract_query_feat(query_loader):
net.eval()
print('Extracting Query Feature...')
start = time.time()
ptr = 0
query_feat_pool = np.zeros((nquery, pool_dim * 3))
query_feat_fc = np.zeros((nquery, pool_dim * 3))
with torch.no_grad():
for batch_idx, (input, label) in enumerate(query_loader):
batch_num = input.size(0)
input = Variable(input.cuda())
feat_pool, feat_fc = net(input, input, label, test_mode[1]) # [192, 2048], [192, 2048]

        feat_pool1, feat_pool2, feat_pool3 = torch.chunk(feat_pool, 3, dim=0)
        feat_fc1, feat_fc2, feat_fc3 = torch.chunk(feat_fc, 3, dim=0)
        feat_pool = torch.cat((feat_pool1, feat_pool2, feat_pool3), 1)
        feat_fc = torch.cat((feat_fc1, feat_fc2, feat_fc3), 1)

        query_feat_pool[ptr:ptr + batch_num, :] = feat_pool.detach().cpu().numpy()
        query_feat_fc[ptr:ptr + batch_num, :] = feat_fc.detach().cpu().numpy()
        ptr = ptr + batch_num
print('Extracting Time:\t {:.3f}'.format(time.time() - start))
return query_feat_pool, query_feat_fc

image

@vk-rrr
Copy link
Author

vk-rrr commented Nov 5, 2024

help!help!

@ccccxxxhhh299
Copy link

解决了吗? 救命!

@vk-rrr
Copy link
Author

vk-rrr commented Nov 7, 2024

我是这么修改的,不知道对不对
def extract_query_feat(query_loader):
net.eval()
print('Extracting Query Feature...')
start = time.time()
ptr = 0
# query_feat_pool = np.zeros((nquery, pool_dim * 3))
# query_feat_fc = np.zeros((nquery, pool_dim * 3))
query_feat_pool1 = np.zeros((nquery, pool_dim))
query_feat_fc1 = np.zeros((nquery, pool_dim))
query_feat_pool2 = np.zeros((nquery, pool_dim))
query_feat_fc2 = np.zeros((nquery, pool_dim))
query_feat_pool3 = np.zeros((nquery, pool_dim))
query_feat_fc3 = np.zeros((nquery, pool_dim))
with torch.no_grad():
for batch_idx, (input, label) in enumerate(query_loader):
batch_num = input.size(0)
input = Variable(input.cuda())
feat_pool, feat_fc = net(input, input, label, test_mode[1]) # [192, 2048], [192, 2048]
#
# feat_pool1, feat_pool2, feat_pool3 = torch.chunk(feat_pool, 3, dim=0)
# feat_fc1, feat_fc2, feat_fc3 = torch.chunk(feat_fc, 3, dim=0)
# feat_pool = torch.cat((feat_pool1, feat_pool2, feat_pool3), 1)
# feat_fc = torch.cat((feat_fc1, feat_fc2, feat_fc3), 1)

        query_feat_pool1[ptr:ptr + batch_num, :] = feat_pool[:batch_num].detach().cpu().numpy()
        query_feat_fc1[ptr:ptr + batch_num, :] = feat_fc[:batch_num].detach().cpu().numpy()
        query_feat_pool2[ptr:ptr + batch_num, :] = feat_pool[batch_num:2 * batch_num].detach().cpu().numpy()
        query_feat_fc2[ptr:ptr + batch_num, :] = feat_fc[batch_num:2 * batch_num].detach().cpu().numpy()
        query_feat_pool3[ptr:ptr + batch_num, :] = feat_pool[batch_num * 2:].detach().cpu().numpy()
        query_feat_fc3[ptr:ptr + batch_num, :] = feat_fc[batch_num * 2:].detach().cpu().numpy()
        ptr = ptr + batch_num
print('Extracting Time:\t {:.3f}'.format(time.time() - start))
query_feat_pool = np.concatenate((query_feat_pool1, query_feat_pool2, query_feat_pool3), axis=0)
query_feat_fc = np.concatenate((query_feat_fc1, query_feat_fc2, query_feat_fc3), axis=0)
return query_feat_pool, query_feat_fc

@vk-rrr
Copy link
Author

vk-rrr commented Nov 7, 2024

tsne.py可视化里的代码怎么改呀,救救

@GG0614
Copy link

GG0614 commented Feb 17, 2025

解决了吗? 救命!

请问你解决了吗?非常感谢可以收到您的回答

@ppsychoo
Copy link

tsne.py可视化里的代码怎么改呀,救救

请问tsne.py改出来了吗

@GG0614
Copy link

GG0614 commented Feb 28, 2025

tsne.py可视化里的代码怎么改呀,救救

请问tsne.py改出来了吗

你改出来了吗 最近我也在进行这项工作

@ppsychoo
Copy link

tsne.py可视化里的代码怎么改呀,救救

请问tsne.py改出来了吗

你改出来了吗 最近我也在进行这项工作

我改出来了,我没有生成特征的mat文件,直接提取特征然后送入到tsne函数里面的

@GG0614
Copy link

GG0614 commented Feb 28, 2025

tsne.py可视化里的代码怎么改呀,救救

请问tsne.py改出来了吗

你改出来了吗 最近我也在进行这项工作

我改出来了,我没有生成特征的mat文件,直接提取特征然后送入到tsne函数里面的

具体是怎么实现的呢?您方便分享一下都在哪些代码文件里做了改动呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants