MCPcopy Create free account
hub / github.com/pytorch/executorch / main

Function main

examples/qualcomm/scripts/inception_v3.py:34–98  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

32
33
34def main(args):
35 qnn_config = QnnConfig.load_config(args.config_file if args.config_file else args)
36 # ensure the working directory exist.
37 os.makedirs(args.artifact, exist_ok=True)
38
39 data_num = 100
40 if args.ci:
41 inputs = [(torch.rand(1, 3, 224, 224),)]
42 logging.warning(
43 "This option is for CI to verify the export flow. It uses random input and will result in poor accuracy."
44 )
45 else:
46 inputs, targets = get_imagenet_dataset(
47 dataset_path=f"{args.dataset}",
48 data_size=data_num,
49 image_shape=(256, 256),
50 crop_size=224,
51 )
52 pte_filename = "ic3_qnn"
53 instance = InceptionV3Model()
54 quant_dtype = {
55 QnnExecuTorchBackendType.kGpuBackend: None,
56 QnnExecuTorchBackendType.kHtpBackend: QuantDtype.use_8a8w,
57 QnnExecuTorchBackendType.kLpaiBackend: QuantDtype.use_8a8w,
58 }[qnn_config.backend]
59
60 build_executorch_binary(
61 model=instance.get_eager_model().eval(),
62 qnn_config=qnn_config,
63 file_name=f"{args.artifact}/{pte_filename}",
64 dataset=inputs,
65 quant_dtype=quant_dtype,
66 )
67
68 adb = SimpleADB(
69 qnn_config=qnn_config,
70 pte_path=f"{args.artifact}/{pte_filename}.pte",
71 workspace=f"/data/local/tmp/executorch/{pte_filename}",
72 )
73 adb.push(inputs=inputs)
74 adb.execute()
75
76 # collect output data
77 output_data_folder = f"{args.artifact}/outputs"
78 make_output_dir(output_data_folder)
79
80 adb.pull(host_output_path=args.artifact)
81
82 # top-k analysis
83 predictions = []
84 for i in range(data_num):
85 predictions.append(
86 np.fromfile(
87 os.path.join(output_data_folder, f"output_{i}_0.raw"), dtype=np.float32
88 )
89 )
90
91 k_val = [1, 5]

Callers 1

inception_v3.pyFile · 0.70

Calls 12

get_eager_modelMethod · 0.95
pushMethod · 0.95
executeMethod · 0.95
pullMethod · 0.95
get_imagenet_datasetFunction · 0.90
InceptionV3ModelClass · 0.90
build_executorch_binaryFunction · 0.90
SimpleADBClass · 0.90
make_output_dirFunction · 0.90
topk_accuracyFunction · 0.90
load_configMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected