11# SPDX-License-Identifier: Apache-2.0
22# Copyright (c) 2024, Ampere Computing LLC
3- import argparse
4- from utils .benchmark import run_model
5- from utils .cv .imagenet import ImageNet
6- from utils .misc import print_goodbye_message_and_die , download_ampere_imagenet
3+ try :
4+ from utils import misc # noqa
5+ except ModuleNotFoundError :
6+ import os
7+ import sys
8+ filename = "set_env_variables.sh"
9+ directory = os .path .realpath (__file__ ).split ("/" )[:- 1 ]
10+ for idx in range (1 , len (directory ) - 1 ):
11+ subdir = "/" .join (directory [:- idx ])
12+ if filename in os .listdir (subdir ):
13+ print (f"\n Please run \033 [91m'source { os .path .join (subdir , filename )} '\033 [0m first." )
14+ break
15+ else :
16+ print (f"\n \033 [91mFAIL: Couldn't find { filename } , are you running this script as part of Ampere Model Library?"
17+ f"\033 [0m" )
18+ sys .exit (1 )
719
820
921def parse_args ():
22+ import argparse
1023 parser = argparse .ArgumentParser (description = "Run Inception v2 model." )
1124 parser .add_argument ("-m" , "--model_path" ,
1225 type = str ,
@@ -37,6 +50,8 @@ def parse_args():
3750
3851
3952def run_tf_fp (model_path , batch_size , num_runs , timeout , images_path , labels_path ):
53+ from utils .benchmark import run_model
54+ from utils .cv .imagenet import ImageNet
4055 from utils .tf import TFFrozenModelRunner
4156
4257 def run_single_pass (tf_runner , imagenet ):
@@ -58,6 +73,8 @@ def run_single_pass(tf_runner, imagenet):
5873
5974
6075def run_tflite (model_path , batch_size , num_runs , timeout , images_path , labels_path ):
76+ from utils .benchmark import run_model
77+ from utils .cv .imagenet import ImageNet
6178 from utils .tflite import TFLiteRunner
6279
6380 def run_single_pass (tflite_runner , imagenet ):
@@ -80,6 +97,8 @@ def run_single_pass(tflite_runner, imagenet):
8097
8198
8299def run_ort_fp (model_path , batch_size , num_runs , timeout , images_path , labels_path ):
100+ from utils .benchmark import run_model
101+ from utils .cv .imagenet import ImageNet
83102 from utils .ort import OrtRunner
84103
85104 def run_single_pass (ort_runner , imagenet ):
@@ -117,6 +136,7 @@ def run_ort_fp16(model_path, batch_size, num_runs, timeout, images_path, labels_
117136
118137
119138def main ():
139+ from utils .misc import print_goodbye_message_and_die , download_ampere_imagenet
120140 args = parse_args ()
121141 download_ampere_imagenet ()
122142
0 commit comments