Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mednet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
medai
software
mednet
Commits
56ce93bd
Commit
56ce93bd
authored
1 year ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
[models] Make alexnet and densenet potentially multi-class classifiers
parent
bd852ec3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Making use of LightningDataModule and simplification of data loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ptbench/models/alexnet.py
+5
-1
5 additions, 1 deletion
src/ptbench/models/alexnet.py
src/ptbench/models/densenet.py
+5
-3
5 additions, 3 deletions
src/ptbench/models/densenet.py
with
10 additions
and
4 deletions
src/ptbench/models/alexnet.py
+
5
−
1
View file @
56ce93bd
...
...
@@ -58,6 +58,9 @@ class Alexnet(pl.LightningModule):
pretrained
If set to True, loads pretrained model weights during initialization,
else trains a new model.
num_classes
Number of outputs (classes) for this model.
"""
def
__init__
(
...
...
@@ -68,6 +71,7 @@ class Alexnet(pl.LightningModule):
optimizer_arguments
:
dict
[
str
,
typing
.
Any
]
=
{},
augmentation_transforms
:
TransformSequence
=
[],
pretrained
:
bool
=
False
,
num_classes
:
int
=
1
,
):
super
().
__init__
()
...
...
@@ -104,7 +108,7 @@ class Alexnet(pl.LightningModule):
# Adapt output features
self
.
model_ft
.
classifier
[
4
]
=
torch
.
nn
.
Linear
(
4096
,
512
)
self
.
model_ft
.
classifier
[
6
]
=
torch
.
nn
.
Linear
(
512
,
1
)
self
.
model_ft
.
classifier
[
6
]
=
torch
.
nn
.
Linear
(
512
,
num_classes
)
def
forward
(
self
,
x
):
x
=
self
.
normalizer
(
x
)
# type: ignore
...
...
This diff is collapsed.
Click to expand it.
src/ptbench/models/densenet.py
+
5
−
3
View file @
56ce93bd
...
...
@@ -56,6 +56,9 @@ class Densenet(pl.LightningModule):
pretrained
If set to True, loads pretrained model weights during initialization,
else trains a new model.
num_classes
Number of outputs (classes) for this model.
"""
def
__init__
(
...
...
@@ -66,6 +69,7 @@ class Densenet(pl.LightningModule):
optimizer_arguments
:
dict
[
str
,
typing
.
Any
]
=
{},
augmentation_transforms
:
TransformSequence
=
[],
pretrained
:
bool
=
False
,
num_classes
:
int
=
1
,
):
super
().
__init__
()
...
...
@@ -101,9 +105,7 @@ class Densenet(pl.LightningModule):
self
.
model_ft
=
models
.
densenet121
(
weights
=
weights
)
# Adapt output features
self
.
model_ft
.
classifier
=
torch
.
nn
.
Sequential
(
torch
.
nn
.
Linear
(
1024
,
256
),
torch
.
nn
.
Linear
(
256
,
1
)
)
self
.
model_ft
.
classifier
=
torch
.
nn
.
Linear
(
1024
,
num_classes
)
def
forward
(
self
,
x
):
x
=
self
.
normalizer
(
x
)
# type: ignore
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment