How to choose the number of output channels in a convolutional layer? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsHow does strided deconvolution works?how to propagate error from convolutional layer to previous layer?Depth of the first pooling layer outcome in tensorflow documentationShould the depth on convolutional layers be set to a figure divisible by 2?How to make output dimensions match input dimensions in CNN?Subsequent convolution layersWhat is the purpose of a 1x1 convolutional layer?Confused about transpose convolution and tensor shapes in tensorflow GAN tuturialChannels in convolutional layer
What LEGO pieces have "real-world" functionality?
What do you call a plan that's an alternative plan in case your initial plan fails?
How can I fade player when goes inside or outside of the area?
If 'B is more likely given A', then 'A is more likely given B'
Disable hyphenation for an entire paragraph
What makes black pepper strong or mild?
Why is "Consequences inflicted." not a sentence?
How can I make names more distinctive without making them longer?
G-Code for resetting to 100% speed
What is the correct way to use the pinch test for dehydration?
Do you forfeit tax refunds/credits if you aren't required to and don't file by April 15?
What do you call a phrase that's not an idiom yet?
How to motivate offshore teams and trust them to deliver?
How widely used is the term Treppenwitz? Is it something that most Germans know?
Why does Python start at index -1 when indexing a list from the end?
How do I keep my slimes from escaping their pens?
Why is black pepper both grey and black?
Is it true that "carbohydrates are of no use for the basal metabolic need"?
Is a manifold-with-boundary with given interior and non-empty boundary essentially unique?
Doubts about chords
What are 'alternative tunings' of a guitar and why would you use them? Doesn't it make it more difficult to play?
What would be the ideal power source for a cybernetic eye?
I am not a queen, who am I?
What are the motives behind Cersei's orders given to Bronn?
How to choose the number of output channels in a convolutional layer?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsHow does strided deconvolution works?how to propagate error from convolutional layer to previous layer?Depth of the first pooling layer outcome in tensorflow documentationShould the depth on convolutional layers be set to a figure divisible by 2?How to make output dimensions match input dimensions in CNN?Subsequent convolution layersWhat is the purpose of a 1x1 convolutional layer?Confused about transpose convolution and tensor shapes in tensorflow GAN tuturialChannels in convolutional layer
$begingroup$
I'm following a pytorch tutorial where for a tensor of shape [8,3,32,32], where 8 is the batch size, 3 the number of channels and 32 x 32, the pixel size, they define the first convolutional layer as nn.Conv2d(3, 16, 5 ), where 3 is the input size, 16 the output size and 5 the kernel size and it works fine.
in_size = 3
hid1_size = 16
hid2_size = 32
out_size = len(labels)
k_conv_size = 5
class ConvNet(nn.Module):
def __init__(self):
super(ConvNet, self).__init__()
self.layer1 = nn.Sequential(
nn.Conv2d(in_size, hid1_size, k_conv_size ),
nn.BatchNorm2d(hid1_size),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2))
self.layer2 = nn.Sequential(
nn.Conv2d(hid1_size, hid2_size, k_conv_size),
nn.BatchNorm2d(hid2_size),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2))
self.fc = nn.Linear(hid2_size * k_conv_size * k_conv_size, out_size)
def forward(self, x):
out = self.layer1(x)
out = self.layer2(out)
out = out.reshape(out.size(0), -1)
out = self.fc(out)
return out
I change the output size from 16 to 32 and that of the next layer from 32 to 64 and it still works.
But when I resize the tensor to have the shape [8, 3, 64, 64], it throws a mismatch error that says size mismatch, m1: [16 x 5408], m2: [800 x 4]
I understand m2 is what it's expecting and m1 is what I'm giving.
But I don't understand where the values of m2 and m1 come from and how to change the hid1_size accordingly.
I understand the relationship between the shape of input data and the neurons in the first layer when building regular linear layers but how to define the relationship between the shape of the input and the number of channels produced by the convolutional layer in cnns?
deep-learning cnn convolution pytorch
$endgroup$
bumped to the homepage by Community♦ 2 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
$begingroup$
I'm following a pytorch tutorial where for a tensor of shape [8,3,32,32], where 8 is the batch size, 3 the number of channels and 32 x 32, the pixel size, they define the first convolutional layer as nn.Conv2d(3, 16, 5 ), where 3 is the input size, 16 the output size and 5 the kernel size and it works fine.
in_size = 3
hid1_size = 16
hid2_size = 32
out_size = len(labels)
k_conv_size = 5
class ConvNet(nn.Module):
def __init__(self):
super(ConvNet, self).__init__()
self.layer1 = nn.Sequential(
nn.Conv2d(in_size, hid1_size, k_conv_size ),
nn.BatchNorm2d(hid1_size),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2))
self.layer2 = nn.Sequential(
nn.Conv2d(hid1_size, hid2_size, k_conv_size),
nn.BatchNorm2d(hid2_size),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2))
self.fc = nn.Linear(hid2_size * k_conv_size * k_conv_size, out_size)
def forward(self, x):
out = self.layer1(x)
out = self.layer2(out)
out = out.reshape(out.size(0), -1)
out = self.fc(out)
return out
I change the output size from 16 to 32 and that of the next layer from 32 to 64 and it still works.
But when I resize the tensor to have the shape [8, 3, 64, 64], it throws a mismatch error that says size mismatch, m1: [16 x 5408], m2: [800 x 4]
I understand m2 is what it's expecting and m1 is what I'm giving.
But I don't understand where the values of m2 and m1 come from and how to change the hid1_size accordingly.
I understand the relationship between the shape of input data and the neurons in the first layer when building regular linear layers but how to define the relationship between the shape of the input and the number of channels produced by the convolutional layer in cnns?
deep-learning cnn convolution pytorch
$endgroup$
bumped to the homepage by Community♦ 2 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
$begingroup$
I'm following a pytorch tutorial where for a tensor of shape [8,3,32,32], where 8 is the batch size, 3 the number of channels and 32 x 32, the pixel size, they define the first convolutional layer as nn.Conv2d(3, 16, 5 ), where 3 is the input size, 16 the output size and 5 the kernel size and it works fine.
in_size = 3
hid1_size = 16
hid2_size = 32
out_size = len(labels)
k_conv_size = 5
class ConvNet(nn.Module):
def __init__(self):
super(ConvNet, self).__init__()
self.layer1 = nn.Sequential(
nn.Conv2d(in_size, hid1_size, k_conv_size ),
nn.BatchNorm2d(hid1_size),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2))
self.layer2 = nn.Sequential(
nn.Conv2d(hid1_size, hid2_size, k_conv_size),
nn.BatchNorm2d(hid2_size),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2))
self.fc = nn.Linear(hid2_size * k_conv_size * k_conv_size, out_size)
def forward(self, x):
out = self.layer1(x)
out = self.layer2(out)
out = out.reshape(out.size(0), -1)
out = self.fc(out)
return out
I change the output size from 16 to 32 and that of the next layer from 32 to 64 and it still works.
But when I resize the tensor to have the shape [8, 3, 64, 64], it throws a mismatch error that says size mismatch, m1: [16 x 5408], m2: [800 x 4]
I understand m2 is what it's expecting and m1 is what I'm giving.
But I don't understand where the values of m2 and m1 come from and how to change the hid1_size accordingly.
I understand the relationship between the shape of input data and the neurons in the first layer when building regular linear layers but how to define the relationship between the shape of the input and the number of channels produced by the convolutional layer in cnns?
deep-learning cnn convolution pytorch
$endgroup$
I'm following a pytorch tutorial where for a tensor of shape [8,3,32,32], where 8 is the batch size, 3 the number of channels and 32 x 32, the pixel size, they define the first convolutional layer as nn.Conv2d(3, 16, 5 ), where 3 is the input size, 16 the output size and 5 the kernel size and it works fine.
in_size = 3
hid1_size = 16
hid2_size = 32
out_size = len(labels)
k_conv_size = 5
class ConvNet(nn.Module):
def __init__(self):
super(ConvNet, self).__init__()
self.layer1 = nn.Sequential(
nn.Conv2d(in_size, hid1_size, k_conv_size ),
nn.BatchNorm2d(hid1_size),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2))
self.layer2 = nn.Sequential(
nn.Conv2d(hid1_size, hid2_size, k_conv_size),
nn.BatchNorm2d(hid2_size),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2))
self.fc = nn.Linear(hid2_size * k_conv_size * k_conv_size, out_size)
def forward(self, x):
out = self.layer1(x)
out = self.layer2(out)
out = out.reshape(out.size(0), -1)
out = self.fc(out)
return out
I change the output size from 16 to 32 and that of the next layer from 32 to 64 and it still works.
But when I resize the tensor to have the shape [8, 3, 64, 64], it throws a mismatch error that says size mismatch, m1: [16 x 5408], m2: [800 x 4]
I understand m2 is what it's expecting and m1 is what I'm giving.
But I don't understand where the values of m2 and m1 come from and how to change the hid1_size accordingly.
I understand the relationship between the shape of input data and the neurons in the first layer when building regular linear layers but how to define the relationship between the shape of the input and the number of channels produced by the convolutional layer in cnns?
deep-learning cnn convolution pytorch
deep-learning cnn convolution pytorch
asked Mar 15 at 7:34
Judy T RajJudy T Raj
1211
1211
bumped to the homepage by Community♦ 2 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 2 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
I recommend you reading the guide to convolution arithmetic for deep learning . There you can find very well written explanations about calculating the about size of your layers depending on kernel size, stride, dilatation, etc.
Further you can easily get your intermediate shapes in pytorch by adding a simple print(x.shape)
statement in your forward pass and adapting your number of neurons in your fully connected layers.
Last but not least. When you cange your input size from 32x32 to 64x64 your output of your final convolutional layer will also have approximately doubled size (depends on kernel size and padding) in each dimension (height, width) and hence you quadruple (double x double) the number of neurons needed in your linear layer.
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47328%2fhow-to-choose-the-number-of-output-channels-in-a-convolutional-layer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
I recommend you reading the guide to convolution arithmetic for deep learning . There you can find very well written explanations about calculating the about size of your layers depending on kernel size, stride, dilatation, etc.
Further you can easily get your intermediate shapes in pytorch by adding a simple print(x.shape)
statement in your forward pass and adapting your number of neurons in your fully connected layers.
Last but not least. When you cange your input size from 32x32 to 64x64 your output of your final convolutional layer will also have approximately doubled size (depends on kernel size and padding) in each dimension (height, width) and hence you quadruple (double x double) the number of neurons needed in your linear layer.
$endgroup$
add a comment |
$begingroup$
I recommend you reading the guide to convolution arithmetic for deep learning . There you can find very well written explanations about calculating the about size of your layers depending on kernel size, stride, dilatation, etc.
Further you can easily get your intermediate shapes in pytorch by adding a simple print(x.shape)
statement in your forward pass and adapting your number of neurons in your fully connected layers.
Last but not least. When you cange your input size from 32x32 to 64x64 your output of your final convolutional layer will also have approximately doubled size (depends on kernel size and padding) in each dimension (height, width) and hence you quadruple (double x double) the number of neurons needed in your linear layer.
$endgroup$
add a comment |
$begingroup$
I recommend you reading the guide to convolution arithmetic for deep learning . There you can find very well written explanations about calculating the about size of your layers depending on kernel size, stride, dilatation, etc.
Further you can easily get your intermediate shapes in pytorch by adding a simple print(x.shape)
statement in your forward pass and adapting your number of neurons in your fully connected layers.
Last but not least. When you cange your input size from 32x32 to 64x64 your output of your final convolutional layer will also have approximately doubled size (depends on kernel size and padding) in each dimension (height, width) and hence you quadruple (double x double) the number of neurons needed in your linear layer.
$endgroup$
I recommend you reading the guide to convolution arithmetic for deep learning . There you can find very well written explanations about calculating the about size of your layers depending on kernel size, stride, dilatation, etc.
Further you can easily get your intermediate shapes in pytorch by adding a simple print(x.shape)
statement in your forward pass and adapting your number of neurons in your fully connected layers.
Last but not least. When you cange your input size from 32x32 to 64x64 your output of your final convolutional layer will also have approximately doubled size (depends on kernel size and padding) in each dimension (height, width) and hence you quadruple (double x double) the number of neurons needed in your linear layer.
answered Mar 15 at 7:49
Andreas LookAndreas Look
449111
449111
add a comment |
add a comment |
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47328%2fhow-to-choose-the-number-of-output-channels-in-a-convolutional-layer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown