Toggle navigation
Toggle navigation
This project
Loading...
Sign in
万朱浩
/
Venue-Ops
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
戒酒的李白
2024-10-15 08:13:08 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
af5e2265eec1dd25c9b2700961df42ee1cfce782
af5e2265
1 parent
3efea929
The final classification layer is complete
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
model_pro/classifier.py
model_pro/classifier.py
0 → 100644
View file @
af5e226
import
torch
import
torch.nn
as
nn
class
FinalClassifier
(
nn
.
Module
):
def
__init__
(
self
,
input_dim
,
num_classes
,
hidden_dim
=
512
,
dropout_rate
=
0.3
):
super
(
FinalClassifier
,
self
)
.
__init__
()
# 增加一个隐藏层
self
.
fc1
=
nn
.
Linear
(
input_dim
,
hidden_dim
)
# 第一层全连接层
self
.
fc2
=
nn
.
Linear
(
hidden_dim
,
num_classes
)
# 第二层全连接层
self
.
dropout
=
nn
.
Dropout
(
dropout_rate
)
# Dropout 防止过拟合
self
.
relu
=
nn
.
ReLU
()
# 激活函数
def
forward
(
self
,
x
):
x
=
self
.
relu
(
self
.
fc1
(
x
))
# 第一层全连接 + ReLU 激活
x
=
self
.
dropout
(
x
)
# Dropout
out
=
self
.
fc2
(
x
)
# 最终输出层(未应用 softmax)
return
out
...
...
Please
register
or
login
to post a comment