|
|
@@ -102,20 +102,21 @@ def test_model(
|
|
|
|
|
|
test_progress = progress.get_sub_tracker("Testing Batches")
|
|
|
test_progress.update(total=len(test_loader), advance=0)
|
|
|
- for _, (mri, xls, targets, _) in enumerate(test_loader):
|
|
|
- _check_control_events(stop_event=stop_event, pause_event=pause_event)
|
|
|
- mri, xls, targets = _move_batch_to_model_device(model, mri, xls, targets)
|
|
|
- outputs = model((mri, xls))
|
|
|
- loss = criterion(outputs, targets)
|
|
|
- batch_size = mri.size(0)
|
|
|
- test_loss += loss.item() * batch_size
|
|
|
- total_samples += batch_size
|
|
|
+ with torch.no_grad():
|
|
|
+ for _, (mri, xls, targets, _) in enumerate(test_loader):
|
|
|
+ _check_control_events(stop_event=stop_event, pause_event=pause_event)
|
|
|
+ mri, xls, targets = _move_batch_to_model_device(model, mri, xls, targets)
|
|
|
+ outputs = model((mri, xls))
|
|
|
+ loss = criterion(outputs, targets)
|
|
|
+ batch_size = mri.size(0)
|
|
|
+ test_loss += loss.item() * batch_size
|
|
|
+ total_samples += batch_size
|
|
|
|
|
|
- # Calculate accuracy
|
|
|
- batch_correct, batch_total = _batch_correct_and_total(outputs, targets)
|
|
|
- correct += batch_correct
|
|
|
- total += batch_total
|
|
|
- test_progress.update(total=len(test_loader), advance=1)
|
|
|
+ # Calculate accuracy
|
|
|
+ batch_correct, batch_total = _batch_correct_and_total(outputs, targets)
|
|
|
+ correct += batch_correct
|
|
|
+ total += batch_total
|
|
|
+ test_progress.update(total=len(test_loader), advance=1)
|
|
|
|
|
|
test_loss = test_loss / total_samples if total_samples > 0 else 0.0
|
|
|
test_acc = correct / total if total > 0 else 0.0
|