Pytorch dynamic forward pass The 2019 Stack Overflow Developer Survey Results Are In 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 ResultsPyTorch vs. Tensorflow FoldHow to install pytorch in windows?Forward and backward process in pyTorchPytorch CapabilitiesWhat is the use of torch.no_grad in pytorch?Inseting pretrained network to pytorchHow to re-initialise batch sampling with pytorch dataloader?static graphs v.s. dynamic graphsReplicating RNN within PyTorch
Can smartphones with the same camera sensor have different image quality?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
How to pronounce 1ターン?
Take groceries in checked luggage
Difference between "generating set" and free product?
Does the AirPods case need to be around while listening via an iOS Device?
Why did all the guest students take carriages to the Yule Ball?
Why can't devices on different VLANs, but on the same subnet, communicate?
When did F become S in typeography, and why?
How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?
Are spiders unable to hurt humans, especially very small spiders?
Windows 10: How to Lock (not sleep) laptop on lid close?
Does Parliament need to approve the new Brexit delay to 31 October 2019?
First use of “packing” as in carrying a gun
How is simplicity better than precision and clarity in prose?
Would it be possible to rearrange a dragon's flight muscle to somewhat circumvent the square-cube law?
Why does the Event Horizon Telescope (EHT) not include telescopes from Africa, Asia or Australia?
The variadic template constructor of my class cannot modify my class members, why is that so?
Would an alien lifeform be able to achieve space travel if lacking in vision?
Typeface like Times New Roman but with "tied" percent sign
What's the point in a preamp?
ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?
How does ice melt when immersed in water
Pytorch dynamic forward pass
The 2019 Stack Overflow Developer Survey Results Are In
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 ResultsPyTorch vs. Tensorflow FoldHow to install pytorch in windows?Forward and backward process in pyTorchPytorch CapabilitiesWhat is the use of torch.no_grad in pytorch?Inseting pretrained network to pytorchHow to re-initialise batch sampling with pytorch dataloader?static graphs v.s. dynamic graphsReplicating RNN within PyTorch
$begingroup$
Does there exist a fast and convenient way for handling such a problem:
class MyModule(nn.Module):
def __init__(self):
super(MyModule, self).__init__()
self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])
def forward(self, x, indices):
x = self.linears[indices](x)
return x
You see i want to access different layers in the network conditioned on an additional input, which is also a list. Further i want to process the whole batch at once and the output.shape != input.shape.
pytorch
$endgroup$
add a comment |
$begingroup$
Does there exist a fast and convenient way for handling such a problem:
class MyModule(nn.Module):
def __init__(self):
super(MyModule, self).__init__()
self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])
def forward(self, x, indices):
x = self.linears[indices](x)
return x
You see i want to access different layers in the network conditioned on an additional input, which is also a list. Further i want to process the whole batch at once and the output.shape != input.shape.
pytorch
$endgroup$
add a comment |
$begingroup$
Does there exist a fast and convenient way for handling such a problem:
class MyModule(nn.Module):
def __init__(self):
super(MyModule, self).__init__()
self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])
def forward(self, x, indices):
x = self.linears[indices](x)
return x
You see i want to access different layers in the network conditioned on an additional input, which is also a list. Further i want to process the whole batch at once and the output.shape != input.shape.
pytorch
$endgroup$
Does there exist a fast and convenient way for handling such a problem:
class MyModule(nn.Module):
def __init__(self):
super(MyModule, self).__init__()
self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])
def forward(self, x, indices):
x = self.linears[indices](x)
return x
You see i want to access different layers in the network conditioned on an additional input, which is also a list. Further i want to process the whole batch at once and the output.shape != input.shape.
pytorch
pytorch
edited Mar 1 at 14:44
Andreas Look
asked Mar 1 at 14:37
Andreas LookAndreas Look
441111
441111
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Here is my understanding of your problem:
# Import
from torch import nn
# Define custom class
class MyModule(nn.Module):
def __init__(self):
super(MyModule, self).__init__()
self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])
def forward(self, x, indices):
x = self.linears[indices](x)
return x
# Intialize custom class
net = MyModule()
# Access networks layers based on additional input
additional_input = 1
if additional_input == 1:
idx = 0
print(net.linears[idx].in_features)
$endgroup$
$begingroup$
thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
$endgroup$
– Andreas Look
Mar 1 at 18:57
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%2f46471%2fpytorch-dynamic-forward-pass%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$
Here is my understanding of your problem:
# Import
from torch import nn
# Define custom class
class MyModule(nn.Module):
def __init__(self):
super(MyModule, self).__init__()
self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])
def forward(self, x, indices):
x = self.linears[indices](x)
return x
# Intialize custom class
net = MyModule()
# Access networks layers based on additional input
additional_input = 1
if additional_input == 1:
idx = 0
print(net.linears[idx].in_features)
$endgroup$
$begingroup$
thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
$endgroup$
– Andreas Look
Mar 1 at 18:57
add a comment |
$begingroup$
Here is my understanding of your problem:
# Import
from torch import nn
# Define custom class
class MyModule(nn.Module):
def __init__(self):
super(MyModule, self).__init__()
self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])
def forward(self, x, indices):
x = self.linears[indices](x)
return x
# Intialize custom class
net = MyModule()
# Access networks layers based on additional input
additional_input = 1
if additional_input == 1:
idx = 0
print(net.linears[idx].in_features)
$endgroup$
$begingroup$
thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
$endgroup$
– Andreas Look
Mar 1 at 18:57
add a comment |
$begingroup$
Here is my understanding of your problem:
# Import
from torch import nn
# Define custom class
class MyModule(nn.Module):
def __init__(self):
super(MyModule, self).__init__()
self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])
def forward(self, x, indices):
x = self.linears[indices](x)
return x
# Intialize custom class
net = MyModule()
# Access networks layers based on additional input
additional_input = 1
if additional_input == 1:
idx = 0
print(net.linears[idx].in_features)
$endgroup$
Here is my understanding of your problem:
# Import
from torch import nn
# Define custom class
class MyModule(nn.Module):
def __init__(self):
super(MyModule, self).__init__()
self.linears = nn.ModuleList([nn.Linear(10, 20) for _ in range(10)])
def forward(self, x, indices):
x = self.linears[indices](x)
return x
# Intialize custom class
net = MyModule()
# Access networks layers based on additional input
additional_input = 1
if additional_input == 1:
idx = 0
print(net.linears[idx].in_features)
answered Mar 1 at 18:32
Brian SpieringBrian Spiering
4,2681129
4,2681129
$begingroup$
thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
$endgroup$
– Andreas Look
Mar 1 at 18:57
add a comment |
$begingroup$
thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
$endgroup$
– Andreas Look
Mar 1 at 18:57
$begingroup$
thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
$endgroup$
– Andreas Look
Mar 1 at 18:57
$begingroup$
thank you brian. i think i didnt specify my problem good enough. by accessing the layers i actually meant to make a forward pass for a whole batch at once, while i need different layers for each entry in the batch conditioned on the extra input
$endgroup$
– Andreas Look
Mar 1 at 18:57
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%2f46471%2fpytorch-dynamic-forward-pass%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