Compile and initialize the model This function will automatically derive the shape of parameters in each sublayer based on the shape of input placeholders. It will also do some settings. Args: inputs(list): the list of input tensors(placeholders)
(self, inputs, is_train=True, use_graph=False, sequential=False)
| 177 | self._results = None |
| 178 | |
| 179 | def compile(self, inputs, is_train=True, use_graph=False, sequential=False): |
| 180 | """ Compile and initialize the model |
| 181 | |
| 182 | This function will automatically derive the shape of parameters |
| 183 | in each sublayer based on the shape of input placeholders. It will |
| 184 | also do some settings. |
| 185 | |
| 186 | Args: |
| 187 | inputs(list): the list of input tensors(placeholders) |
| 188 | is_train(bool): when is_trainis True, this model will enter |
| 189 | training mode, otherwise it will enter the evaluation mode |
| 190 | use_graph(bool): when use_graph is True, computational graph |
| 191 | will be used to train this model |
| 192 | sequential(bool): when sequential is True, model will execute ops |
| 193 | in the graph follow the order of joining the graph |
| 194 | """ |
| 195 | assert len(inputs) > 0 and isinstance(inputs[0], Tensor), ( |
| 196 | 'compile function expects PlaceHolders or Tensors') |
| 197 | |
| 198 | dev = inputs[0].device |
| 199 | dev.EnableGraph(True) |
| 200 | self.forward(*inputs) |
| 201 | dev.EnableGraph(False) |
| 202 | dev.ResetGraph() |
| 203 | |
| 204 | autograd.training = is_train |
| 205 | self.training = is_train |
| 206 | self.graph_mode = use_graph |
| 207 | self.sequential = sequential |
| 208 | |
| 209 | def forward(self, *input): |
| 210 | """Defines the computation performed in every forward propagation. |
no test coverage detected