Skip to content

Commit c1ace0e

Browse files
authored
Qualcomm AI Engine Direct - DeepLabV3 Example Script Fix (pytorch#21973)
### Summary Community user has reported issue with deeplabv3 script: pytorch#21870 Instead of casting to a list, use data_loader to handle, which should avoid opening too many files. ### Test plan Verified E2E script still works
1 parent 04d14b0 commit c1ace0e

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

‎examples/qualcomm/scripts/deeplab_v3.py‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import json
88
import logging
99
import os
10-
import random
1110
import re
1211
from multiprocessing.connection import Client
1312

@@ -41,23 +40,23 @@ def get_dataset(data_size, dataset_dir, download):
4140
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
4241
]
4342
)
44-
dataset = list(
45-
datasets.VOCSegmentation(
46-
root=os.path.join(dataset_dir, "voc_image"),
47-
year="2012",
48-
image_set="val",
49-
transform=preprocess,
50-
download=download,
51-
)
43+
dataset = datasets.VOCSegmentation(
44+
root=os.path.join(dataset_dir, "voc_image"),
45+
year="2012",
46+
image_set="val",
47+
transform=preprocess,
48+
download=download,
49+
)
50+
51+
data_loader = torch.utils.data.DataLoader(
52+
dataset, shuffle=True, collate_fn=lambda batch: batch[0]
5253
)
5354

5455
# prepare input data
55-
random.shuffle(dataset)
5656
inputs, targets = [], []
57-
for index, data in enumerate(dataset):
57+
for index, (image, target) in enumerate(data_loader):
5858
if index >= data_size:
5959
break
60-
image, target = data
6160
inputs.append((image.unsqueeze(0),))
6261
targets.append(np.array(target.resize(input_size)))
6362

0 commit comments

Comments
 (0)