(net, outputs, outputs_with_grad, input_values, inputs_with_grads)
| 38 | |
| 39 | |
| 40 | def _get_grad(net, outputs, outputs_with_grad, input_values, inputs_with_grads): |
| 41 | grad_net = net.Clone(net.Name() + "_copy") |
| 42 | grad_map = grad_net.AddGradientOperators(outputs_with_grad) |
| 43 | |
| 44 | for name, value in (input_values or {}).items(): |
| 45 | workspace.blobs[name] = value |
| 46 | |
| 47 | for input_to_check in inputs_with_grads: |
| 48 | assert input_to_check in grad_map, ( |
| 49 | '{} has no gradient, cannot check net gradient.'.format( |
| 50 | input_to_check)) |
| 51 | assert str(input_to_check) in workspace.blobs |
| 52 | |
| 53 | workspace.RunNetOnce(grad_net) |
| 54 | forward_results = [(output, workspace.blobs[output]) for output in outputs] |
| 55 | grads = {input_to_check: _get_grad_blob(grad_map, input_to_check) |
| 56 | for input_to_check in inputs_with_grads} |
| 57 | |
| 58 | return forward_results, grads, grad_net |
| 59 | |
| 60 | |
| 61 | def _assert_close(value1, value2, threshold, err_msg=''): |
no test coverage detected
searching dependent graphs…