Args: config (PredictConfig): the config to use. towers: a list of relative GPU id.
(self, config, towers)
| 88 | """ |
| 89 | |
| 90 | def __init__(self, config, towers): |
| 91 | """ |
| 92 | Args: |
| 93 | config (PredictConfig): the config to use. |
| 94 | towers: a list of relative GPU id. |
| 95 | """ |
| 96 | self.graph = config._maybe_create_graph() |
| 97 | with self.graph.as_default(): |
| 98 | input_tensors = [] |
| 99 | output_tensors = [] |
| 100 | |
| 101 | for idx, t in enumerate(towers): |
| 102 | tower_name = 'tower' + str(t) |
| 103 | |
| 104 | new_sig = [tf.TensorSpec(dtype=p.dtype, shape=p.shape, name=tower_name + '_' + p.name) |
| 105 | for p in config.input_signature] |
| 106 | input = PlaceholderInput() |
| 107 | input.setup(new_sig) |
| 108 | |
| 109 | with tf.variable_scope(tf.get_variable_scope(), reuse=idx > 0), \ |
| 110 | tf.device('/gpu:{}'.format(t)), \ |
| 111 | PredictTowerContext(tower_name): |
| 112 | config.tower_func(*input.get_input_tensors()) |
| 113 | h = config.tower_func.towers[-1] |
| 114 | input_tensors.extend(h.get_tensors(config.input_names)) |
| 115 | output_tensors.extend(h.get_tensors(config.output_names)) |
| 116 | |
| 117 | config.session_init._setup_graph() |
| 118 | sess = config.session_creator.create_session() |
| 119 | config.session_init._run_init(sess) |
| 120 | super(DataParallelOfflinePredictor, self).__init__( |
| 121 | input_tensors, output_tensors, config.return_input, sess) |
nothing calls this directly
no test coverage detected