Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hyunji
/
A-Performance-Evaluation-of-CNN-for-Brain-Age-Prediction-Using-Structural-MRI-Data
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Hyunji
2021-12-20 03:49:35 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e30d6c257d17b5da37724a4309831045e8a53df2
e30d6c25
1 parent
198c41b4
3D-CNN, VGGNet model
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
252 additions
and
0 deletions
3DCNN_VGGNet_2DResNet/model.py
3DCNN_VGGNet_2DResNet/model.py
0 → 100644
View file @
e30d6c2
import
torch.nn.functional
as
F
import
torch.nn
as
nn
from
torch.autograd
import
Variable
class
Model
(
nn
.
Module
):
def
__init__
(
self
):
super
(
Model
,
self
)
.
__init__
()
self
.
features
=
nn
.
Sequential
(
nn
.
Conv2d
(
121
,
64
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
64
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
# nn.Dropout2d(),
nn
.
Conv2d
(
64
,
32
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
32
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
nn
.
Conv2d
(
32
,
16
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
16
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
)
)
self
.
classifier
=
nn
.
Sequential
(
nn
.
Linear
(
4320
,
1024
),
# nn.BatchNorm1d(1024),
nn
.
ReLU
(),
nn
.
Dropout
(),
nn
.
Linear
(
1024
,
512
),
# nn.BatchNorm1d(512),
nn
.
ReLU
(),
nn
.
Dropout
(),
nn
.
Linear
(
512
,
1
),
# nn.BatchNorm1d(),
nn
.
ReLU
()
)
# self.linear1 = nn.Linear()
def
forward
(
self
,
x
):
x
=
self
.
features
(
x
)
x
=
self
.
classifier
(
x
.
view
(
-
1
,
x
.
shape
[
1
]
*
x
.
shape
[
2
]
*
x
.
shape
[
3
]))
# print(x.shape)
return
x
class
VGGBasedModel
(
nn
.
Module
):
def
__init__
(
self
):
super
(
VGGBasedModel
,
self
)
.
__init__
()
self
.
features
=
nn
.
Sequential
(
nn
.
Conv2d
(
121
,
128
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
128
),
nn
.
ReLU
(),
nn
.
Conv2d
(
128
,
128
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
128
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
nn
.
Conv2d
(
128
,
256
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
256
),
nn
.
ReLU
(),
nn
.
Conv2d
(
256
,
256
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
256
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
nn
.
Conv2d
(
256
,
512
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
512
),
nn
.
ReLU
(),
nn
.
Conv2d
(
512
,
512
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
512
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
nn
.
Conv2d
(
512
,
512
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
512
),
nn
.
ReLU
(),
nn
.
Conv2d
(
512
,
512
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
512
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
nn
.
Conv2d
(
512
,
256
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
256
),
nn
.
ReLU
(),
nn
.
Conv2d
(
256
,
256
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
256
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
)
self
.
classifier
=
nn
.
Sequential
(
nn
.
Linear
(
3072
,
2048
),
# nn.BatchNorm1d(1024),
nn
.
ReLU
(),
nn
.
Dropout
(),
nn
.
Linear
(
2048
,
1024
),
nn
.
ReLU
(),
nn
.
Dropout
(),
nn
.
Linear
(
1024
,
512
),
nn
.
ReLU
(),
nn
.
Dropout
(),
nn
.
Linear
(
512
,
1
),
# nn.BatchNorm1d(),
nn
.
ReLU
()
)
def
forward
(
self
,
x
):
x
=
self
.
features
(
x
)
x
=
self
.
classifier
(
x
.
view
(
-
1
,
x
.
shape
[
1
]
*
x
.
shape
[
2
]
*
x
.
shape
[
3
]))
# print(x.shape)
return
x
class
VGGBasedModel2D
(
nn
.
Module
):
def
__init__
(
self
):
super
(
VGGBasedModel2D
,
self
)
.
__init__
()
self
.
features
=
nn
.
Sequential
(
nn
.
Conv2d
(
1
,
128
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
128
),
nn
.
ReLU
(),
nn
.
Conv2d
(
128
,
128
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
128
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
nn
.
Conv2d
(
128
,
256
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
256
),
nn
.
ReLU
(),
nn
.
Conv2d
(
256
,
256
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
256
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
nn
.
Conv2d
(
256
,
512
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
512
),
nn
.
ReLU
(),
nn
.
Conv2d
(
512
,
512
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
512
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
nn
.
Conv2d
(
512
,
512
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
512
),
nn
.
ReLU
(),
nn
.
Conv2d
(
512
,
512
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
512
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
nn
.
Conv2d
(
512
,
256
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
256
),
nn
.
ReLU
(),
nn
.
Conv2d
(
256
,
256
,
3
,
padding
=
1
),
nn
.
BatchNorm2d
(
256
),
nn
.
ReLU
(),
nn
.
MaxPool2d
(
2
),
)
self
.
classifier
=
nn
.
Sequential
(
nn
.
Linear
(
3072
,
2048
),
# nn.BatchNorm1d(1024),
nn
.
ReLU
(),
nn
.
Dropout
(),
nn
.
Linear
(
2048
,
1024
),
nn
.
ReLU
(),
nn
.
Dropout
(),
nn
.
Linear
(
1024
,
512
),
nn
.
ReLU
(),
nn
.
Dropout
(),
nn
.
Linear
(
512
,
1
),
# nn.BatchNorm1d(),
nn
.
ReLU
()
)
def
forward
(
self
,
x
):
x
=
self
.
features
(
x
)
x
=
self
.
classifier
(
x
.
view
(
-
1
,
x
.
shape
[
1
]
*
x
.
shape
[
2
]
*
x
.
shape
[
3
]))
# print(x.shape)
return
x
class
Model3D
(
nn
.
Module
):
def
__init__
(
self
):
super
(
Model3D
,
self
)
.
__init__
()
self
.
block1
=
nn
.
Sequential
(
nn
.
Conv3d
(
1
,
8
,
3
,
stride
=
1
),
nn
.
ReLU
(),
nn
.
Conv3d
(
8
,
8
,
3
,
stride
=
1
),
nn
.
BatchNorm3d
(
8
),
nn
.
ReLU
(),
nn
.
MaxPool3d
(
2
,
stride
=
2
))
self
.
block2
=
nn
.
Sequential
(
nn
.
Conv3d
(
8
,
16
,
3
,
stride
=
1
),
nn
.
ReLU
(),
nn
.
Conv3d
(
16
,
16
,
3
,
stride
=
1
),
nn
.
BatchNorm3d
(
16
),
nn
.
ReLU
(),
nn
.
MaxPool3d
(
2
,
stride
=
2
))
self
.
block3
=
nn
.
Sequential
(
nn
.
Conv3d
(
16
,
32
,
3
,
stride
=
1
),
nn
.
ReLU
(),
nn
.
Conv3d
(
32
,
32
,
3
,
stride
=
1
),
nn
.
BatchNorm3d
(
32
),
nn
.
ReLU
(),
nn
.
MaxPool3d
(
2
,
stride
=
2
))
self
.
block4
=
nn
.
Sequential
(
nn
.
Conv3d
(
32
,
64
,
3
,
stride
=
1
,
padding
=
1
),
nn
.
ReLU
(),
nn
.
Conv3d
(
64
,
64
,
3
,
stride
=
1
,
padding
=
1
),
nn
.
BatchNorm3d
(
64
),
nn
.
ReLU
(),
nn
.
MaxPool3d
(
2
,
stride
=
2
))
self
.
block5
=
nn
.
Sequential
(
nn
.
Conv3d
(
64
,
128
,
3
,
stride
=
1
,
padding
=
1
),
nn
.
ReLU
(),
nn
.
Conv3d
(
128
,
128
,
3
,
stride
=
1
,
padding
=
1
),
nn
.
BatchNorm3d
(
128
),
nn
.
ReLU
(),
nn
.
MaxPool3d
(
2
,
stride
=
2
)
)
self
.
classifier
=
nn
.
Linear
(
1536
,
1
)
def
forward
(
self
,
x
):
x
=
self
.
block1
(
x
)
# print(x.shape)
x
=
self
.
block2
(
x
)
# print(x.shape)
x
=
self
.
block3
(
x
)
# print(x.shape)
x
=
self
.
block4
(
x
)
# print(x.shape)
x
=
self
.
block5
(
x
)
# print(x.shape)
x
=
self
.
classifier
(
x
.
view
(
-
1
,
x
.
shape
[
1
]
*
x
.
shape
[
2
]
*
x
.
shape
[
3
]
*
x
.
shape
[
4
]))
# print(x.shape)
return
x
\ No newline at end of file
Please
register
or
login
to post a comment