Artificial Intelligence Asked by petsol on October 12, 2020
I would like to bind kernel parameters through channels/feature-maps for each filter. In a conv2d operation, each filter consists of HxWxC parameters I would like to have filters that have HxW parameters, but the same (HxWxC) form.
The scenario I have is that I have 4 gray pictures of bulb samples (yielding similar images from each side), which I overlay as channels, but a possible failure that needs to be detected might only appear on one side (a bulb has 4 images and a single classification). The rotation of the object when the picture is taken is arbitrary. Now I solve this by shuffling the channels at training, but it would be more efficient if I could just bind the kernel parameters. Pytorch and Tensorflow solutions are both welcome.
Assuming you want HxWx1 kernel to perform convolution on hxwxc images.
Here's sample code which uses single channel kernel to operate on multichannel feature: maps
import torch
import torch.nn as nn
import torch.nn.functional as F
class model(nn.Module):
def __init__(self, in_ch=4):
super().__init__()
self.in_ch = in_ch
# single channel kernel initialization
self.kernel = nn.Conv2d(in_channels=1, out_channels=1, kernel_size=1, stride=1)
def forward(self, x):
bs, ch, w, h = x.shape
x = x.view((bs, ch, 1, w, h))
out = self.kernel(x[:, 0])
# reusing of same kernel
for i in range(1, self.in_ch):
out = torch.cat((out, self.kernel(x[:, i])), 1)
return out
net = model(4)
print(net)
inp = torch.randn((10, 4, 100, 100))
out = net(inp)
print(out.shape)
(The main hack is in the forward
function)
Answered by Girish Dattatray Hegde on October 12, 2020
0 Asked on December 16, 2021
0 Asked on December 16, 2021 by sirfroggy
bellman equations convergence proofs q learning reinforcement learning
1 Asked on December 13, 2021
convergence deep rl dqn function approximation reinforcement learning
1 Asked on December 13, 2021
3 Asked on December 11, 2021
categorical crossentropy comparison machine learning mean squared error objective functions
1 Asked on December 11, 2021
attention deep learning natural language processing transformer
1 Asked on December 11, 2021 by sports_stats
algorithm cross validation machine learning support vector machine
2 Asked on December 9, 2021
0 Asked on December 9, 2021 by blba
algorithmic bias neural networks reference request regularization training
0 Asked on December 9, 2021 by i_al-thamary
1 Asked on December 7, 2021
1 Asked on December 7, 2021 by jr123456jr987654321
activation function convolutional neural networks neural networks relu residual networks
1 Asked on December 7, 2021
data preprocessing machine learning neural networks normalisation standardisation
1 Asked on December 4, 2021 by nilsinelabore
convolutional neural networks keras machine learning neural networks
3 Asked on December 2, 2021 by pnar-demetci
deep learning deep neural networks feedforward neural network machine learning neural networks
2 Asked on December 2, 2021
geometric deep learning graph neural networks resource request
2 Asked on November 29, 2021 by ipsumpanest
6 Asked on November 29, 2021
bayesian deep learning convolutional neural networks keras tensorflow uncertainty quantification
1 Asked on November 29, 2021 by sanmu
architecture convolutional neural networks deep learning neural networks
1 Asked on November 29, 2021 by unter_983
actor critic methods ddpg policy gradients reinforcement learning
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP