(self,
checkpoint_path,
shape,
use_gpu,
is_fused,
restore=False,
freeze_mode=False,
dtype=dtypes.float32)
| 65 | return loss, train_op, saver |
| 66 | |
| 67 | def _train(self, |
| 68 | checkpoint_path, |
| 69 | shape, |
| 70 | use_gpu, |
| 71 | is_fused, |
| 72 | restore=False, |
| 73 | freeze_mode=False, |
| 74 | dtype=dtypes.float32): |
| 75 | ops.reset_default_graph() |
| 76 | graph = ops.get_default_graph() |
| 77 | with self.session(graph=graph, use_gpu=use_gpu) as sess: |
| 78 | image = array_ops.placeholder(dtype=dtype, shape=shape) |
| 79 | loss, train_op, saver = self._simple_model(image, is_fused, freeze_mode) |
| 80 | if restore: |
| 81 | saver.restore(sess, checkpoint_path) |
| 82 | else: |
| 83 | self.evaluate(variables.global_variables_initializer()) |
| 84 | np.random.seed(0) |
| 85 | for _ in range(2): |
| 86 | image_val = np.random.rand(*shape).astype(dtype.as_numpy_dtype) |
| 87 | sess.run([loss, train_op], feed_dict={image: image_val}) |
| 88 | if restore: |
| 89 | all_vars = ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES) |
| 90 | all_vars_values = [var.eval() for var in all_vars] |
| 91 | return all_vars_values |
| 92 | else: |
| 93 | saver.save(sess, checkpoint_path) |
| 94 | |
| 95 | def _infer(self, checkpoint_path, image_val, shape, use_gpu, is_fused): |
| 96 | dtype = image_val.dtype |
no test coverage detected