Compute input gradient of batches.