-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nChannels not according to paper #16
Open
PabloRR100
wants to merge
4
commits into
bamos:master
Choose a base branch
from
PabloRR100:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,14 +58,14 @@ def forward(self, x): | |
|
||
|
||
class DenseNet(nn.Module): | ||
def __init__(self, growthRate, depth, reduction, nClasses, bottleneck): | ||
def __init__(self, growthRate, depth, reduction, nClasses, bottleneck, compression): | ||
super(DenseNet, self).__init__() | ||
|
||
nDenseBlocks = (depth-4) // 3 | ||
if bottleneck: | ||
nDenseBlocks //= 2 | ||
|
||
nChannels = 2*growthRate | ||
nChannels = 2*growthRate if compression and bottleneck else 16 # They only do this for BC type | ||
self.conv1 = nn.Conv2d(3, nChannels, kernel_size=3, padding=1, | ||
bias=False) | ||
self.dense1 = self._make_dense(nChannels, growthRate, nDenseBlocks, bottleneck) | ||
|
@@ -84,6 +84,7 @@ def __init__(self, growthRate, depth, reduction, nClasses, bottleneck): | |
nChannels += nDenseBlocks*growthRate | ||
|
||
self.bn1 = nn.BatchNorm2d(nChannels) | ||
self.avgpool = nn.AvgPool2d(kernel_size=8) | ||
self.fc = nn.Linear(nChannels, nClasses) | ||
|
||
for m in self.modules(): | ||
|
@@ -111,6 +112,49 @@ def forward(self, x): | |
out = self.trans1(self.dense1(out)) | ||
out = self.trans2(self.dense2(out)) | ||
out = self.dense3(out) | ||
out = torch.squeeze(F.avg_pool2d(F.relu(self.bn1(out)), 8)) | ||
out = F.log_softmax(self.fc(out)) | ||
#out = torch.squeeze(F.avg_pool2d(F.relu(self.bn1(out)), 8)) ## Why did you relu and bn again? | ||
out = self.avgpool(8) | ||
# out = F.log_softmax(self.fc(out)) | ||
out = self.fc(out) # You can define the softmax within the loss function right? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, this part shouldn't have been changed |
||
return out | ||
|
||
|
||
def denseNet_40_12(): | ||
return DenseNet(12, 40, 1, 10, bottleneck=False, compression=False) | ||
|
||
def denseNet_100_12(): | ||
return DenseNet(12, 100, 1, 10, bottleneck=False, compression=False) | ||
|
||
def denseNet_100_24(): | ||
return DenseNet(24, 100, 1, 10, bottleneck=False, compression=False) | ||
|
||
def denseNetBC_100_12(): | ||
return DenseNet(12, 100, 0.5, 10, bottleneck=True, compression=True) | ||
|
||
def denseNetBC_250_24(): | ||
return DenseNet(24, 250, 0.5, 10, bottleneck=True, compression=True) | ||
|
||
def denseNetBC_190_40(): | ||
return DenseNet(40, 190, 0.5, 10, bottleneck=True, compression=True) | ||
|
||
|
||
''' Did this little check: | ||
DenseNets implemented on the paper <https://arxiv.org/pdf/1608.06993.pdf> | ||
|
||
+-------------+-------------+-------+--------------+ | ||
| Model | Growth Rate | Depth | M. of Params | | ||
+-------------+-------------+-------+--------------+ | ||
| DenseNet | 12 | 40 | 1.02 | | ||
+-------------+-------------+-------+--------------+ | ||
| DenseNet | 12 | 100 | 6.98 | | ||
+-------------+-------------+-------+--------------+ | ||
| DenseNet | 24 | 100 | 27.249 | | ||
+-------------+-------------+-------+--------------+ | ||
| DenseNet-BC | 12 | 100 | 0.769 | | ||
+-------------+-------------+-------+--------------+ | ||
| DenseNet-BC | 24 | 250 | 15.324 | | ||
+-------------+-------------+-------+--------------+ | ||
| DenseNet-BC | 40 | 190 | 25.624 | | ||
+-------------+-------------+-------+--------------+ | ||
|
||
'''' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, adding
self.avgpool
is a stylistic change. I prefer keeping thetorch.functional
verison. Also shouldn'tout
be input the pooling layer? How is this code working?