简体   繁体   English

通过应用掩码提取部分卷积神经网络特征

[英]Extracting a part of the convolutional neural network feature through application of a mask

So i have my final feature of shape (1, 512, 90, 160) with 512 as the depth(3rd dimension).所以我有我最后的形状特征(1, 512, 90, 160) ,深度为 512(第三维)。 I have created a 2-D binary mask from the ground truth image of shape (90, 160) .我从形状(90, 160)的地面实况图像创建了一个二维二进制掩码。 I am trying to apply this mask to the feature to extract only a part of my feature manually.我正在尝试将此掩码应用于该功能以仅手动提取我的部分功能。 However due to the mismatch in the shapes of feature and the mask, I get the index error.然而,由于特征和掩码的形状不匹配,我得到了索引错误。

With np.expand_dims() , I have made shape of the mask to be (1,1,90,160) .使用np.expand_dims() ,我将掩码的形状设为(1,1,90,160) Now, How can I get to stack the mask to get the shape (1, 512, 90, 160) ?现在,我怎样才能堆叠遮罩以获得形状(1, 512, 90, 160)

You have 2 options:您有 2 个选择:

Create a 3d mask-创建一个 3d 蒙版-

final = np.ones((1,512,90,160))
final2 = np.copy(final)
mask = np.random.randint(1,10,size = (1,90,160)) > np.random.randint(1,10,size = (1,90,160))

masked = np.copy(final)
masked[:,0,:,:] = np.logical_and(masked[:,0,:,:],mask)
masked = np.logical_and.accumulate(masked,axis = 1)
np.putmask(final,masked == False, 0)

The above will create a 3d mask, and use it to mask final .以上将创建一个 3d 蒙版,并用它来蒙版final

the other option, much simpler, is to just multiply:另一种更简单的选择是乘法:

np.multiply(final,mask)

NP handles the dimensions, and will give you the masked version. NP 处理尺寸,并为您提供屏蔽版本。

You can verify this by:您可以通过以下方式验证:

(np.multiply(final2,mask) == final).all()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM