Skip to content

Commit 4f42d20

Browse files
committed
try_to_allocate_tensor_on_cpu
1 parent af49d6d commit 4f42d20

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

modAL/dropout.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,11 @@ def get_predictions(classifier: BaseEstimator, X: modALinput, dropout_layer_inde
317317
logits = classifier.estimator.infer(samples)
318318
prediction = logits_adaptor(logits, samples)
319319

320-
if probas is None: probas = torch.empty((number_of_samples, prediction.shape[-1]), device=prediction.device)
321-
probas[range(sample_per_forward_pass*index, sample_per_forward_pass*(index+1)), :] = prediction
320+
mask = ~prediction.isnan()
321+
prediction[mask] = prediction[mask].unsqueeze(0).softmax(1)
322+
if probas is None: probas = torch.empty((number_of_samples, prediction.shape[-1]), device='cpu')
323+
probas[range(sample_per_forward_pass*index, sample_per_forward_pass*(index+1)), :] = prediction.cpu()
322324

323-
324-
mask = ~probas.isnan()
325-
probas[mask] = probas[mask].unsqueeze(0).softmax(1)
326325
probas = to_numpy(probas)
327326
predictions.append(probas)
328327

0 commit comments

Comments
 (0)