MCPcopy Index your code
hub / github.com/yosinski/deep-visualization-toolbox / CaffeProcThread

Class CaffeProcThread

caffevis/caffe_proc_thread.py:11–150  ·  view source on GitHub ↗

Runs Caffe in separate thread.

Source from the content-addressed store, hash-verified

9
10
11class CaffeProcThread(CodependentThread):
12 '''Runs Caffe in separate thread.'''
13
14 def __init__(self, settings, net, state, loop_sleep, pause_after_keys, heartbeat_required, mode_gpu):
15 CodependentThread.__init__(self, heartbeat_required)
16 self.daemon = True
17 self.net = net
18 self.input_dims = self.net.blobs['data'].data.shape[2:4] # e.g. (227,227)
19 self.state = state
20 self.last_process_finished_at = None
21 self.last_process_elapsed = None
22 self.frames_processed_fwd = 0
23 self.frames_processed_back = 0
24 self.loop_sleep = loop_sleep
25 self.pause_after_keys = pause_after_keys
26 self.debug_level = 0
27 self.mode_gpu = mode_gpu # Needed so the mode can be set again in the spawned thread, because there is a separate Caffe object per thread.
28
29 self.settings = settings
30
31
32 def run(self):
33 print 'CaffeProcThread.run called'
34 frame = None
35
36 import caffe
37 # Set the mode to CPU or GPU. Note: in the latest Caffe
38 # versions, there is one Caffe object *per thread*, so the
39 # mode must be set per thread! Here we set the mode for the
40 # CaffeProcThread thread; it is also set in the main thread.
41 if self.mode_gpu:
42 caffe.set_mode_gpu()
43 print 'CaffeVisApp mode (in CaffeProcThread): GPU'
44 else:
45 caffe.set_mode_cpu()
46 print 'CaffeVisApp mode (in CaffeProcThread): CPU'
47
48 while not self.is_timed_out():
49 with self.state.lock:
50 if self.state.quit:
51 #print 'CaffeProcThread.run: quit is True'
52 #print self.state.quit
53 break
54
55 #print 'CaffeProcThread.run: caffe_net_state is:', self.state.caffe_net_state
56
57 #print 'CaffeProcThread.run loop: next_frame: %s, caffe_net_state: %s, back_enabled: %s' % (
58 # 'None' if self.state.next_frame is None else 'Avail',
59 # self.state.caffe_net_state,
60 # self.state.back_enabled)
61
62 frame = None
63 run_fwd = False
64 run_back = False
65 if self.state.caffe_net_state == 'free' and time.time() - self.state.last_key_at > self.pause_after_keys:
66 frame = self.state.next_frame
67 self.state.next_frame = None
68 back_enabled = self.state.back_enabled

Callers 1

startMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected