From eec36805516bd947eecd72d94905e3b9ddf59621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BC=9F=E6=A0=B9?= <1101204667@qq.com> Date: Mon, 28 Mar 2022 08:57:07 +0000 Subject: [PATCH 1/3] update main.py. --- .../DeepLabV3+_ID0458_for_PyTorch/main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py b/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py index a73edf6404..ee2378b9bd 100644 --- a/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py +++ b/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py @@ -397,7 +397,12 @@ def main(): model.train() cur_epochs += 1 end = time.time() - for (images, labels) in train_loader: + + data_prefetcher_stream = torch.npu.Stream() + from torch.contrib.npu.optimized_lib.module.prefetcher import Prefetcher as Prefetcher + prefetcher = Prefetcher(train_loader, stream=data_prefetcher_stream) + images,labels = prefetcher.next() + while images is not None: cur_itrs += 1 images = images.to(f'npu:{NPU_CALCULATE_DEVICE}', dtype=torch.float32, non_blocking=True) -- Gitee From c0299b192b4e92a8cfb0f8e3d2b22c04e33595b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BC=9F=E6=A0=B9?= <1101204667@qq.com> Date: Mon, 28 Mar 2022 10:48:41 +0000 Subject: [PATCH 2/3] update main.py. --- .../image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py b/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py index ee2378b9bd..552e5f607a 100644 --- a/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py +++ b/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py @@ -460,7 +460,8 @@ def main(): if cur_itrs >= opts.total_itrs: return - + images,labels = prefetcher.next() + class AverageMeter(object): """Computes and stores the average and current value""" def __init__(self): -- Gitee From 7f05577bd27055fee4affb14738a4ac79ee1e489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BC=9F=E6=A0=B9?= <1101204667@qq.com> Date: Tue, 29 Mar 2022 02:38:37 +0000 Subject: [PATCH 3/3] update main.py. --- .../cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py b/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py index 552e5f607a..600ee7a856 100644 --- a/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py +++ b/PyTorch/dev/cv/image_segmentation/DeepLabV3+_ID0458_for_PyTorch/main.py @@ -56,6 +56,7 @@ import torch.npu import apex from apex import amp,optimizers import sys +from torch.contrib.npu.optimized_lib.module.prefetcher import Prefetcher as Prefetcher import os NPU_CALCULATE_DEVICE = 0 @@ -399,7 +400,6 @@ def main(): end = time.time() data_prefetcher_stream = torch.npu.Stream() - from torch.contrib.npu.optimized_lib.module.prefetcher import Prefetcher as Prefetcher prefetcher = Prefetcher(train_loader, stream=data_prefetcher_stream) images,labels = prefetcher.next() while images is not None: -- Gitee