Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
546af8b2
Commit
546af8b2
authored
Mar 19, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add function to set rng seed
parent
dfaa63eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletion
+20
-1
examples/mnist-convnet.py
examples/mnist-convnet.py
+2
-1
tensorpack/utils/utils.py
tensorpack/utils/utils.py
+18
-0
No files found.
examples/mnist-convnet.py
View file @
546af8b2
...
...
@@ -135,7 +135,8 @@ def get_config():
logger
.
auto_set_dir
()
dataset_train
,
dataset_test
=
get_data
()
# how many iterations you want in each epoch
# How many iterations you want in each epoch.
# This is the default value, don't actually need to set it in the config
steps_per_epoch
=
dataset_train
.
size
()
# get the config which contains everything necessary in a training
...
...
tensorpack/utils/utils.py
View file @
546af8b2
...
...
@@ -13,6 +13,7 @@ import numpy as np
__all__
=
[
'change_env'
,
'get_rng'
,
'fix_rng_seed'
,
'get_tqdm_kwargs'
,
'get_tqdm'
,
'execute_only_once'
,
...
...
@@ -38,6 +39,21 @@ def change_env(name, val):
os
.
environ
[
name
]
=
oldval
_RNG_SEED
=
None
def
fix_rng_seed
(
seed
):
"""
Args:
seed (int):
Note:
See https://github.com/ppwwyyxx/tensorpack/issues/196.
"""
global
_RNG_SEED
_RNG_SEED
=
int
(
seed
)
def
get_rng
(
obj
=
None
):
"""
Get a good RNG seeded with time, pid and the object.
...
...
@@ -49,6 +65,8 @@ def get_rng(obj=None):
"""
seed
=
(
id
(
obj
)
+
os
.
getpid
()
+
int
(
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S
%
f"
)))
%
4294967295
if
_RNG_SEED
is
not
None
:
seed
=
_RNG_SEED
return
np
.
random
.
RandomState
(
seed
)
...
...
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