(grad_map, input_to_check)
| 18 | |
| 19 | |
| 20 | def _get_grad_blob(grad_map, input_to_check): |
| 21 | grad_blob = grad_map[input_to_check] |
| 22 | |
| 23 | if isinstance(grad_blob, core.BlobReference): |
| 24 | return workspace.blobs[grad_blob] |
| 25 | |
| 26 | # If grad_blob is not a single blob, it should be a gradient slice. |
| 27 | # To make it comparable with the estimiated gradient which is dense, |
| 28 | # we need to first convert grad_blob to dense gradient. |
| 29 | assert isinstance(grad_blob, core.GradientSlice) |
| 30 | dense_grad = 'tmp_dense_grad' |
| 31 | sparse_to_dense_op = core.CreateOperator( |
| 32 | 'SparseToDense', |
| 33 | [grad_blob.indices, grad_blob.values, input_to_check], |
| 34 | dense_grad, |
| 35 | ) |
| 36 | workspace.RunOperatorOnce(sparse_to_dense_op) |
| 37 | return workspace.blobs[dense_grad] |
| 38 | |
| 39 | |
| 40 | def _get_grad(net, outputs, outputs_with_grad, input_values, inputs_with_grads): |
no test coverage detected
searching dependent graphs…