Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Swin-Transformer-Object-Detection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wanggh
Swin-Transformer-Object-Detection
Commits
300f7157
Commit
300f7157
authored
6 years ago
by
Kai Chen
Browse files
Options
Downloads
Patches
Plain Diff
allow manually setting random seeds
parent
143a8372
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/train.py
+13
-0
13 additions, 0 deletions
tools/train.py
with
13 additions
and
0 deletions
tools/train.py
+
13
−
0
View file @
300f7157
...
...
@@ -4,6 +4,7 @@ import argparse
import
logging
from
collections
import
OrderedDict
import
numpy
as
np
import
torch
from
mmcv
import
Config
from
mmcv.torchpack
import
Runner
,
obj_from_dict
...
...
@@ -53,6 +54,12 @@ def get_logger(log_level):
return
logger
def
set_random_seed
(
seed
):
np
.
random
.
seed
(
seed
)
torch
.
manual_seed
(
seed
)
torch
.
cuda
.
manual_seed_all
(
seed
)
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'
Train a detector
'
)
parser
.
add_argument
(
'
config
'
,
help
=
'
train config file path
'
)
...
...
@@ -63,6 +70,7 @@ def parse_args():
help
=
'
whether to add a validate phase
'
)
parser
.
add_argument
(
'
--gpus
'
,
type
=
int
,
default
=
1
,
help
=
'
number of gpus to use
'
)
parser
.
add_argument
(
'
--seed
'
,
type
=
int
,
help
=
'
random seed
'
)
parser
.
add_argument
(
'
--launcher
'
,
choices
=
[
'
none
'
,
'
pytorch
'
,
'
slurm
'
,
'
mpi
'
],
...
...
@@ -84,6 +92,11 @@ def main():
logger
=
get_logger
(
cfg
.
log_level
)
# set random seed if specified
if
args
.
seed
is
not
None
:
logger
.
info
(
'
Set random seed to {}
'
.
format
(
args
.
seed
))
set_random_seed
(
args
.
seed
)
# init distributed environment if necessary
if
args
.
launcher
==
'
none
'
:
dist
=
False
...
...
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