Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hi-template
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴磊(20博)
hi-template
Commits
bddb0704
Commit
bddb0704
authored
Apr 05, 2022
by
吴磊(20博)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
6fe67be4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
0 deletions
+5
-0
train_mnist.py
train/train_mnist.py
+5
-0
No files found.
train/train_mnist.py
View file @
bddb0704
...
...
@@ -33,6 +33,7 @@ def train(rank, world_size, args):
Resize
(
224
),
Normalize
((
0.485
,
0.456
,
0.406
),
(
0.229
,
0.224
,
0.2
))
])
dataset
=
torchvision
.
datasets
.
CIFAR100
(
"./CIFAR100"
,
transform
=
transform
)
train_sampler
=
DistributedSampler
(
dataset
,
world_size
,
rank
,
True
)
data_loader
=
torch
.
utils
.
data
.
DataLoader
(
dataset
,
...
...
@@ -45,7 +46,11 @@ def train(rank, world_size, args):
params
=
[
p
for
p
in
model
.
parameters
()
if
p
.
requires_grad
]
optimizer
=
torch
.
optim
.
Adam
(
params
)
# we can apply multiple loss functions on multiple outputs.
# loss = [{"loss_1_1": loss_1_1, "loss_1_2": loss_1_2}, {"loss_2_1": loss_2_1, "loss_2_2": loss_2_2}]
loss_func
=
[{
"ce"
:
torch
.
nn
.
CrossEntropyLoss
()
.
to
(
rank
)}]
# the weights of every output.
loss_weights
=
[
1.
]
model
=
DDP
(
model
,
device_ids
=
[
rank
],
output_device
=
rank
,
find_unused_parameters
=
False
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment