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
c12cf88b
Commit
c12cf88b
authored
Jun 06, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trainer & concurrency
parent
8e4c695c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
14 deletions
+22
-14
tensorpack/train/trainer.py
tensorpack/train/trainer.py
+7
-4
tensorpack/utils/concurrency.py
tensorpack/utils/concurrency.py
+15
-10
No files found.
tensorpack/train/trainer.py
View file @
c12cf88b
...
@@ -17,7 +17,8 @@ from ..utils.concurrency import LoopThread
...
@@ -17,7 +17,8 @@ from ..utils.concurrency import LoopThread
from
..tfutils.summary
import
summary_moving_average
from
..tfutils.summary
import
summary_moving_average
from
..tfutils
import
*
from
..tfutils
import
*
__all__
=
[
'SimpleTrainer'
,
'QueueInputTrainer'
,
'start_train'
]
__all__
=
[
'SimpleTrainer'
,
'QueueInputTrainer'
,
'AsyncMultiGPUTrainer'
,
'SyncMultiGPUTrainer'
]
class
SimpleTrainer
(
Trainer
):
class
SimpleTrainer
(
Trainer
):
def
run_step
(
self
):
def
run_step
(
self
):
...
@@ -269,7 +270,9 @@ class QueueInputTrainer(Trainer):
...
@@ -269,7 +270,9 @@ class QueueInputTrainer(Trainer):
return
[
self
.
get_predict_func
(
input_names
,
output_names
,
k
)
return
[
self
.
get_predict_func
(
input_names
,
output_names
,
k
)
for
k
in
range
(
n
)]
for
k
in
range
(
n
)]
def
start_train
(
config
):
def
AsyncMultiGPUTrainer
(
config
):
tr
=
QueueInputTrainer
(
config
)
return
QueueInputTrainer
(
config
,
async
=
True
)
tr
.
train
()
def
SyncMultiGPUTrainer
(
config
):
return
QueueInputTrainer
(
config
)
tensorpack/utils/concurrency.py
View file @
c12cf88b
...
@@ -55,28 +55,33 @@ class StoppableThread(threading.Thread):
...
@@ -55,28 +55,33 @@ class StoppableThread(threading.Thread):
except
queue
.
Empty
:
except
queue
.
Empty
:
pass
pass
class
LoopThread
(
threading
.
Thread
):
class
LoopThread
(
Stoppable
Thread
):
""" A pausable thread that simply runs a loop"""
""" A pausable thread that simply runs a loop"""
def
__init__
(
self
,
func
):
def
__init__
(
self
,
func
,
pausable
=
True
):
"""
"""
:param func: the function to run
:param func: the function to run
"""
"""
super
(
LoopThread
,
self
)
.
__init__
()
super
(
LoopThread
,
self
)
.
__init__
()
self
.
func
=
func
self
.
_func
=
func
self
.
lock
=
threading
.
Lock
()
self
.
_pausable
=
pausable
if
pausable
:
self
.
_lock
=
threading
.
Lock
()
self
.
daemon
=
True
self
.
daemon
=
True
def
run
(
self
):
def
run
(
self
):
while
True
:
while
not
self
.
stopped
():
self
.
lock
.
acquire
()
if
self
.
_pausable
:
self
.
lock
.
release
()
self
.
_lock
.
acquire
()
self
.
func
()
self
.
_lock
.
release
()
self
.
_func
()
def
pause
(
self
):
def
pause
(
self
):
self
.
lock
.
acquire
()
assert
self
.
_pausable
self
.
_lock
.
acquire
()
def
resume
(
self
):
def
resume
(
self
):
self
.
lock
.
release
()
assert
self
.
_pausable
self
.
_lock
.
release
()
class
DIE
(
object
):
class
DIE
(
object
):
...
...
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