diff --git a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/timit/steps/train_ctc.py b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/timit/steps/train_ctc.py index d3508aaf1350407914e7f4e078482e9cc7e15329..3417344713a3d69303df8b7c0aea03aa27a6df3b 100644 --- a/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/timit/steps/train_ctc.py +++ b/PyTorch/built-in/nlp/LSTM_ID0468_for_PyTorch/timit/steps/train_ctc.py @@ -86,8 +86,8 @@ def run_epoch(epoch_id, model, data_iter, loss_fn, device, optimizer=None, print input_sizes = (input_sizes * out_len).long() loss = loss_fn(out, targets, input_sizes, target_sizes) loss /= batch_size - cur_loss += loss.item() - total_loss += loss.item() + cur_loss += loss.detach() + total_loss += loss.detach() prob, index = torch.max(out, dim=-1) batch_errs, batch_tokens = model.compute_wer(index.transpose(0,1).cpu().numpy(), input_sizes.cpu().numpy(), targets.cpu().numpy(), target_sizes.cpu().numpy()) total_errs += batch_errs diff --git a/PyTorch/dev/cv/image_classification/FasterRCNN_ID0100_for_PyTorch/detectron2/engine/train_loop.py b/PyTorch/dev/cv/image_classification/FasterRCNN_ID0100_for_PyTorch/detectron2/engine/train_loop.py index e40ba95b01aac527683e0fcb5ee0d534606ce81b..3d8228f21af267c830d1b5a8db545f47b542b400 100644 --- a/PyTorch/dev/cv/image_classification/FasterRCNN_ID0100_for_PyTorch/detectron2/engine/train_loop.py +++ b/PyTorch/dev/cv/image_classification/FasterRCNN_ID0100_for_PyTorch/detectron2/engine/train_loop.py @@ -293,7 +293,7 @@ class SimpleTrainer(TrainerBase): metrics_dict (dict): dict of scalar metrics """ metrics_dict = { - k: v.detach().cpu().item() if isinstance(v, torch.Tensor) else float(v) + k: v.detach()if isinstance(v, torch.Tensor) else float(v) for k, v in metrics_dict.items() } # gather metrics among all workers for logging diff --git a/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/detectron2/modeling/proposal_generator/rpn.py b/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/detectron2/modeling/proposal_generator/rpn.py index cbb097537550077a9af168f796e5aab1323f7431..c1e264fe65e953efc5a5ee554170ce2d412a34fd 100644 --- a/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/detectron2/modeling/proposal_generator/rpn.py +++ b/PyTorch/dev/cv/image_classification/MaskRCNN_ID0101_for_PyTorch/detectron2/modeling/proposal_generator/rpn.py @@ -384,8 +384,8 @@ class RPN(nn.Module): # Log the number of positive/negative anchors per-image that's used in training pos_mask = gt_labels == 1 - num_pos_anchors = pos_mask.sum().item() - num_neg_anchors = (gt_labels == 0).sum().item() + num_pos_anchors = pos_mask.sum().detach() + num_neg_anchors = (gt_labels == 0).sum().detach() storage = get_event_storage() storage.put_scalar("rpn/num_pos_anchors", num_pos_anchors / num_images) storage.put_scalar("rpn/num_neg_anchors", num_neg_anchors / num_images)