(self, image, label)
| 339 | tf.TensorSpec([None], tf.int32, 'label')] |
| 340 | |
| 341 | def build_graph(self, image, label): |
| 342 | image = self.image_preprocess(image) |
| 343 | assert self.data_format in ['NCHW', 'NHWC'] |
| 344 | if self.data_format == 'NCHW': |
| 345 | image = tf.transpose(image, [0, 3, 1, 2]) |
| 346 | |
| 347 | logits = self.get_logits(image) |
| 348 | tf.nn.softmax(logits, name='prob') |
| 349 | loss = ImageNetModel.compute_loss_and_error( |
| 350 | logits, label, label_smoothing=self.label_smoothing) |
| 351 | |
| 352 | if self.weight_decay > 0: |
| 353 | wd_loss = regularize_cost(self.weight_decay_pattern, |
| 354 | l2_regularizer(self.weight_decay), |
| 355 | name='l2_regularize_loss') |
| 356 | add_moving_summary(loss, wd_loss) |
| 357 | total_cost = tf.add_n([loss, wd_loss], name='cost') |
| 358 | else: |
| 359 | total_cost = tf.identity(loss, name='cost') |
| 360 | add_moving_summary(total_cost) |
| 361 | |
| 362 | if self.loss_scale != 1.: |
| 363 | logger.info("Scaling the total loss by {} ...".format(self.loss_scale)) |
| 364 | return total_cost * self.loss_scale |
| 365 | else: |
| 366 | return total_cost |
| 367 | |
| 368 | @abstractmethod |
| 369 | def get_logits(self, image): |
nothing calls this directly
no test coverage detected