如何在Python中至少加入三个2D阵列?

发布于 2025-01-17 14:30:01 字数 280 浏览 0 评论 0原文

我正在做面向目标的图像字幕。它具有三种模式——特征提取、OCR 组件和对象检测。从 ResNeXt 模型中提取的特征被重新整形为大小为 (49, 2048) 的张量。 OCR 和对象检测组件分别最多有 20 个和 10 个单词,每个维度为 (300,1)。我想使用线性投影将这些向量连接/嵌入到维度 d=512 的联合空间中。我该怎么做?

我使用了 axis=None 的 numpy.concatenate 函数,它线性连接输出,尺寸为 100652,但我希望输出如上所述,带有 (512,n),因为我必须将连接输出传递给解码器。

I am doing goal-oriented image captioning. It has three modalities- features extracted, OCR component and object detection. The features extracted from ResNeXt model is reshaped into a tensor of size (49, 2048). The OCR and Object Detection components have a maximum of 20 and 10 words respectively, each of dimension (300,1). I want to concatenate/embed these vectors into a joint space of dimension d=512 using linear projection. How can I do this?

I used numpy.concatenate function with axis=None, it concatenated the output linearly and had a dimension of 100652 but I want the output as mentioned above with (512,n) as I have to pass the concatenated output to decoder.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪也成诗 2025-01-24 14:30:01

说明使用不同的连接:

In [32]: alist = [np.ones((2,4),int)*i for i in range(1,4)]
In [33]: alist
Out[33]: 
[array([[1, 1, 1, 1],
        [1, 1, 1, 1]]),
 array([[2, 2, 2, 2],
        [2, 2, 2, 2]]),
 array([[3, 3, 3, 3],
        [3, 3, 3, 3]])]
In [34]: np.concatenate(alist,axis=0)
Out[34]: 
array([[1, 1, 1, 1],
       [1, 1, 1, 1],
       [2, 2, 2, 2],
       [2, 2, 2, 2],
       [3, 3, 3, 3],
       [3, 3, 3, 3]])
In [35]: np.concatenate(alist,axis=1)
Out[35]: 
array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3],
       [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]])
In [36]: np.concatenate(alist,axis=None)
Out[36]: 
array([1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
       3, 3])

这与您从阅读文档中期望的有什么不同吗?

Illustrating concatenate with different axis:

In [32]: alist = [np.ones((2,4),int)*i for i in range(1,4)]
In [33]: alist
Out[33]: 
[array([[1, 1, 1, 1],
        [1, 1, 1, 1]]),
 array([[2, 2, 2, 2],
        [2, 2, 2, 2]]),
 array([[3, 3, 3, 3],
        [3, 3, 3, 3]])]
In [34]: np.concatenate(alist,axis=0)
Out[34]: 
array([[1, 1, 1, 1],
       [1, 1, 1, 1],
       [2, 2, 2, 2],
       [2, 2, 2, 2],
       [3, 3, 3, 3],
       [3, 3, 3, 3]])
In [35]: np.concatenate(alist,axis=1)
Out[35]: 
array([[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3],
       [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]])
In [36]: np.concatenate(alist,axis=None)
Out[36]: 
array([1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
       3, 3])

Is that any different from what you expect from reading the docs?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文