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

Function main

examples/qualcomm/oss_scripts/fbnet.py:31–103  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

29
30
31def main(args):
32 qnn_config = QnnConfig.load_config(args.config_file if args.config_file else args)
33
34 # ensure the working directory exist.
35 os.makedirs(args.artifact, exist_ok=True)
36
37 instance = timm.create_model("fbnetc_100", pretrained=True).eval()
38
39 data_num = 100
40 inputs, targets = get_imagenet_dataset(
41 dataset_path=f"{args.dataset}",
42 data_size=data_num,
43 image_shape=(299, 299),
44 )
45
46 pte_filename = "fbnet_qnn"
47
48 quant_dtype = {
49 QnnExecuTorchBackendType.kGpuBackend: None,
50 QnnExecuTorchBackendType.kHtpBackend: QuantDtype.use_8a8w,
51 }[qnn_config.backend]
52 build_executorch_binary(
53 model=instance,
54 qnn_config=qnn_config,
55 file_name=f"{args.artifact}/{pte_filename}",
56 dataset=inputs,
57 quant_dtype=quant_dtype,
58 )
59
60 adb = SimpleADB(
61 qnn_config=qnn_config,
62 pte_path=f"{args.artifact}/{pte_filename}.pte",
63 workspace=f"/data/local/tmp/executorch/{pte_filename}",
64 )
65 adb.push(inputs=inputs)
66 adb.execute()
67
68 # collect output data
69 output_data_folder = f"{args.artifact}/outputs"
70 make_output_dir(output_data_folder)
71
72 output_raws = []
73
74 def post_process():
75 for f in sorted(
76 os.listdir(output_data_folder), key=lambda f: int(f.split("_")[1])
77 ):
78 filename = os.path.join(output_data_folder, f)
79 if re.match(r"^output_[0-9]+_[1-9].raw$", f):
80 os.remove(filename)
81 else:
82 output = np.fromfile(filename, dtype=np.float32)
83 output_raws.append(output)
84
85 adb.pull(host_output_path=args.artifact, callback=post_process)
86
87 # top-k analysis
88 predictions = []

Callers 1

fbnet.pyFile · 0.70

Calls 11

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

Tested by

no test coverage detected