(args)
| 31 | |
| 32 | |
| 33 | def main(args): |
| 34 | qnn_config = QnnConfig.load_config(args.config_file if args.config_file else args) |
| 35 | |
| 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 | |
| 53 | module = ( |
| 54 | AutoModelForImageClassification.from_pretrained("Zetatech/pvt-tiny-224") |
| 55 | .eval() |
| 56 | .to("cpu") |
| 57 | ) |
| 58 | |
| 59 | pte_filename = "pvt_qnn" |
| 60 | quant_dtype = { |
| 61 | QnnExecuTorchBackendType.kGpuBackend: None, |
| 62 | QnnExecuTorchBackendType.kHtpBackend: QuantDtype.use_8a8w, |
| 63 | }[qnn_config.backend] |
| 64 | build_executorch_binary( |
| 65 | model=module.eval(), |
| 66 | qnn_config=qnn_config, |
| 67 | file_name=f"{args.artifact}/{pte_filename}", |
| 68 | dataset=inputs, |
| 69 | quant_dtype=quant_dtype, |
| 70 | ) |
| 71 | |
| 72 | adb = SimpleADB( |
| 73 | qnn_config=qnn_config, |
| 74 | pte_path=f"{args.artifact}/{pte_filename}.pte", |
| 75 | workspace=f"/data/local/tmp/executorch/{pte_filename}", |
| 76 | ) |
| 77 | adb.push(inputs=inputs) |
| 78 | adb.execute() |
| 79 | |
| 80 | # collect output data |
| 81 | output_data_folder = f"{args.artifact}/outputs" |
| 82 | make_output_dir(output_data_folder) |
| 83 | |
| 84 | adb.pull(host_output_path=args.artifact) |
| 85 | |
| 86 | # top-k analysis |
| 87 | predictions = [] |
| 88 | for i in range(data_num): |
| 89 | predictions.append( |
| 90 | np.fromfile( |
no test coverage detected