question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dear @Cadene, Thank you for your fantastic repository. I want to modify NASNet (i.e., apply some minor modifications on NASNet by remove Dropout, add sigmoid layer at the end of net and etc.). I have implemented below code:

import torch
from torch.autograd import Variable
import torch.nn.functional as F
import torch.nn as nn
from nasnet import nasnetalarge

num_classes = 10

# *** Define Modified NASNet Class:
class ModifiedNASNet(nn.Module):
    def __init__(self, num_classes):
        super(ModifiedNASNet, self).__init__()

        original_model = nasnetalarge(num_classes=1000, pretrained='imagenet')

        # Everything except the last classifier:
        self.features = nn.Sequential(*list(original_model.children())[:-4])

        # Set number of features:
        num_feats = 4032

        # Plug our linear layer:
        self.classifier = nn.Sequential(nn.Linear(num_feats, num_classes))

    def forward(self, x):
        f = self.features(x)
        out = F.relu(f, inplace=True)
        out = F.avg_pool2d(out, kernel_size=11, stride=1, padding=0, ceil_mode=False, count_include_pad=True)
        out = out.view(out.size(0), -1) # Flatten
        out = self.classifier(out)
        out = F.sigmoid(out)
        return out

# *** test above class:
model = ModifiedNASNet(num_classes).cuda()
# print(model)
x = Variable(torch.randn(1, 3, 331, 331), volatile=True).cuda()
out = model(x)
print(out)

However, the following error has occurred: TypeError: forward() missing 1 required positional argument: 'x_stem_0' Would you please kindly help me to address this problem?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
emitedcommented, Nov 20, 2017

In the nn.Sequential container, a module’s output is taken as the next module’s input. But self.cell_stem1 takes input from both previous modules, self.conv0 and self.cell_stem_1. Try something like this:

import torch
from torch.autograd import Variable
import torch.nn.functional as F
from nasnet import NASNetALarge


class ModifiedNASNet(NASNetALarge):

    def classifier(self, x):
        out = F.relu(f, inplace=True)
        out = F.avg_pool2d(out, kernel_size=11, stride=1, padding=0, ceil_mode=False, count_include_pad=True)
        out = out.view(out.size(0), -1) # Flatten
        out = self.linear(out)
        out = F.sigmoid(out)
        return out        


# *** test above class:
model = ModifiedNASNet(num_classes).cuda()
# print(model)
x = Variable(torch.randn(1, 3, 331, 331), volatile=True).cuda()
out = model(x)
print(out)
0reactions
emitedcommented, Dec 17, 2018

Hello @ClimbsRocks. It has been a long time since I used this library… @Cadene ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to customize the first Reduction cells in NASnet-A ...
How to customize the first Reduction cells in NASnet-A according to variable input image size? In the 2018 Zoph et al paper, the...
Read more >
NASNet
NASNet is a type of convolutional neural network discovered through neural architecture search. The building blocks consist of normal and reduction cells.
Read more >
Review: NASNet — Neural Architecture Search Network ...
In this story, NASNet, by Google Brain, is reviewed. Authors propose to search for an architectural building block on a small dataset and ......
Read more >
From AlexNet to NASNet: A Brief History and Introduction of ...
From AlexNet to NASNet: A Brief History and Introduction of Convolutional ... go through 2 convolution layers without changing image' size
Read more >
Deep Learning ToolboxTM Model for NASNet-Large Network
Deep Learning ToolboxTM Model for NASNet-Large Network ... Pretrained NasNet-Large network model for image classification ... Adjust size of the image
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found