parameters: (self, model)
docstring: generate model file with new batch size which equal to bkm batch size
docstring_summary: generate model file with new batch size which equal to bkm batch size
docstring_tokens: generate model file with new batch size which equal to bkm batch size
function: def gen_model_file(self, model):
          '''generate model file with new batch size which equal to bkm batch size'''
          if model.find("_int8") != -1: 
              if not self.test_mode == "inf_throughput" and not self.test_mode == "inf_latency":
                  print("Error: int8 test is only for inference")
                  return ""
                    
              prototxt_file=model+".prototxt"
              if model == "resnet50_int8" :
                  prototxt_file="resnet50_int8_full_conv.prototxt"
  
              
              if model == "faster-rcnn_int8":
                   dst_model_file = self.model_path + "/faster-rcnn/pascal_voc/VGG16/faster_rcnn_end2end/" + self.cpu_model + "_" + "test_int8.prototxt"
              elif model == "rfcn_int8":
                   dst_model_file = self.model_path + "/rfcn/pascal_voc/ResNet-101/rfcn_end2end/" + self.cpu_model + "_" + "test_agnostic_int8.prototxt"
              else:
                   dst_model_file = os.path.join(self.model_path, './int8/', '-'.join([self.cpu_model, prototxt_file]))    
  
              if os.path.isfile(dst_model_file):
                  os.remove(dst_model_file)
  
              if model == "faster-rcnn_int8":
                   src_model_file = self.model_path + "/faster-rcnn/pascal_voc/VGG16/faster_rcnn_end2end/test_int8.prototxt"
              elif model == "rfcn_int8":
                   src_model_file = self.model_path + "/rfcn/pascal_voc/ResNet-101/rfcn_end2end/test_agnostic_int8.prototxt"
              else: 
                   src_model_file = os.path.join(self.model_path, './int8/', prototxt_file)
  
              print("source model "+src_model_file)
              if not os.path.isfile(src_model_file):
                  logging.exception("template model file {} doesn't exist.".format(src_model_file))
              print("dest model "+model)
              if model.find("ssd") == -1 or model.find("yolo") == -1:
                  batch_size_cnt = 1
              else:
                  batch_size_cnt = 2
              if model not in self.inf_bkm_batch_size or self.cpu_model not in self.inf_bkm_batch_size[model]:
                  logging.exception("Can't find batch size of topology {} and cpu model {} within batch size table".format(model, self.cpu_model))
              batch_size_pattern = re.compile(".*dim.*")
              new_batch_size = self.inf_bkm_batch_size[model][self.cpu_model]
              if self.test_mode == "inf_latency":
                  new_batch_size="1" 
              with open(src_model_file, 'r') as src_f, open(dst_model_file, 'w') as dst_f:
                  cnt = 0
                  line2=""
                  for line in src_f.readlines():
                      if line2 != "" and ( line2.find("shape") != -1 or line.find("input: \"data\"") != -1 ) and re.match(batch_size_pattern, line) and cnt < batch_size_cnt:
                          #change batch size
                          line = re.sub("[0-9]+", new_batch_size, line, count = 1)
                          cnt += 1
                      dst_f.write(line) 
                      line2=line
              return dst_model_file
          else:
              if self.test_mode == "inf_throughput" or self.test_mode == "inf_latency":
                  prototxt_file = "deploy.prototxt"
              else:
                  prototxt_file = "train_val_dummydata.prototxt" if self.dummy_data_use else "train_val.prototxt"
              dst_model_file = os.path.join(self.model_path, './benchmark/', model, '-'.join([self.cpu_model, prototxt_file]))
              if os.path.isfile(dst_model_file):
                  os.remove(dst_model_file)
              src_model_file = os.path.join(self.model_path, './benchmark/', model, './', prototxt_file)
              if not os.path.isfile(src_model_file):
                  logging.exception("template model file {} doesn't exist.".format(src_model_file))
  
              if model == "ssd" and ( self.test_mode == "inf_throughput" or self.test_mode == "inf_latency" ):
                  batch_size_pattern = re.compile(".*input_shape {.*") if self.dummy_data_use else re.compile("^\s+batch_size:.*")
              else: 
                  if model == "mobilenet_v2" and ( self.test_mode == "inf_throughput" or self.test_mode == "inf_latency" ):
                      batch_size_pattern = re.compile(".*input_dim.*") if self.dummy_data_use else re.compile("^\s+batch_size:.*")
                  else:
                      batch_size_pattern = re.compile(".*shape:.*") if self.dummy_data_use else re.compile("^\s+batch_size:.*")
  
              batch_size_cnt = 2
              if self.test_mode == "train_throughput" or self.test_mode == "scal_test":
                  if model not in self.train_bkm_batch_size or self.test_mode == "train_throughput" and self.cpu_model not in self.train_bkm_batch_size[model]:
                      logging.exception("Can't find batch size of topology {} and cpu model {} within batch size table".format(model, self.cpu_model))
                  new_batch_size = self.train_bkm_batch_size[model] if self.test_mode == "scal_test" else self.train_bkm_batch_size[model][self.cpu_model]
              else:
                  if model not in self.inf_bkm_batch_size or self.cpu_model not in self.inf_bkm_batch_size[model]:
                      logging.exception("Can't find batch size of topology {} and cpu model {} within batch size table".format(model, self.cpu_model))
                  new_batch_size = self.inf_bkm_batch_size[model][self.cpu_model]
                  if self.test_mode == "inf_latency":
                      new_batch_size="1"
       
              with open(src_model_file, 'r') as src_f, open(dst_model_file, 'w') as dst_f:
                  cnt = 0
                  for line in src_f.readlines():
                      if re.match(batch_size_pattern, line) and cnt < batch_size_cnt:
                          #change batch size
                          line = re.sub("[0-9]+", new_batch_size, line, count = 1)
                          cnt += 1
                      dst_f.write(line) 
              return dst_model_file
function_tokens: def gen_model_file ( self , model ) : if model . find ( "_int8" ) != - 1 : if not self . test_mode == "inf_throughput" and not self . test_mode == "inf_latency" : print ( "Error: int8 test is only for inference" ) return "" prototxt_file = model + ".prototxt" if model == "resnet50_int8" : prototxt_file = "resnet50_int8_full_conv.prototxt" if model == "faster-rcnn_int8" : dst_model_file = self . model_path + "/faster-rcnn/pascal_voc/VGG16/faster_rcnn_end2end/" + self . cpu_model + "_" + "test_int8.prototxt" elif model == "rfcn_int8" : dst_model_file = self . model_path + "/rfcn/pascal_voc/ResNet-101/rfcn_end2end/" + self . cpu_model + "_" + "test_agnostic_int8.prototxt" else : dst_model_file = os . path . join ( self . model_path , './int8/' , '-' . join ( [ self . cpu_model , prototxt_file ] ) ) if os . path . isfile ( dst_model_file ) : os . remove ( dst_model_file ) if model == "faster-rcnn_int8" : src_model_file = self . model_path + "/faster-rcnn/pascal_voc/VGG16/faster_rcnn_end2end/test_int8.prototxt" elif model == "rfcn_int8" : src_model_file = self . model_path + "/rfcn/pascal_voc/ResNet-101/rfcn_end2end/test_agnostic_int8.prototxt" else : src_model_file = os . path . join ( self . model_path , './int8/' , prototxt_file ) print ( "source model " + src_model_file ) if not os . path . isfile ( src_model_file ) : logging . exception ( "template model file {} doesn't exist." . format ( src_model_file ) ) print ( "dest model " + model ) if model . find ( "ssd" ) == - 1 or model . find ( "yolo" ) == - 1 : batch_size_cnt = 1 else : batch_size_cnt = 2 if model not in self . inf_bkm_batch_size or self . cpu_model not in self . inf_bkm_batch_size [ model ] : logging . exception ( "Can't find batch size of topology {} and cpu model {} within batch size table" . format ( model , self . cpu_model ) ) batch_size_pattern = re . compile ( ".*dim.*" ) new_batch_size = self . inf_bkm_batch_size [ model ] [ self . cpu_model ] if self . test_mode == "inf_latency" : new_batch_size = "1" with open ( src_model_file , 'r' ) as src_f , open ( dst_model_file , 'w' ) as dst_f : cnt = 0 line2 = "" for line in src_f . readlines ( ) : if line2 != "" and ( line2 . find ( "shape" ) != - 1 or line . find ( "input: \"data\"" ) != - 1 ) and re . match ( batch_size_pattern , line ) and cnt < batch_size_cnt : #change batch size line = re . sub ( "[0-9]+" , new_batch_size , line , count = 1 ) cnt += 1 dst_f . write ( line ) line2 = line return dst_model_file else : if self . test_mode == "inf_throughput" or self . test_mode == "inf_latency" : prototxt_file = "deploy.prototxt" else : prototxt_file = "train_val_dummydata.prototxt" if self . dummy_data_use else "train_val.prototxt" dst_model_file = os . path . join ( self . model_path , './benchmark/' , model , '-' . join ( [ self . cpu_model , prototxt_file ] ) ) if os . path . isfile ( dst_model_file ) : os . remove ( dst_model_file ) src_model_file = os . path . join ( self . model_path , './benchmark/' , model , './' , prototxt_file ) if not os . path . isfile ( src_model_file ) : logging . exception ( "template model file {} doesn't exist." . format ( src_model_file ) ) if model == "ssd" and ( self . test_mode == "inf_throughput" or self . test_mode == "inf_latency" ) : batch_size_pattern = re . compile ( ".*input_shape {.*" ) if self . dummy_data_use else re . compile ( "^\s+batch_size:.*" ) else : if model == "mobilenet_v2" and ( self . test_mode == "inf_throughput" or self . test_mode == "inf_latency" ) : batch_size_pattern = re . compile ( ".*input_dim.*" ) if self . dummy_data_use else re . compile ( "^\s+batch_size:.*" ) else : batch_size_pattern = re . compile ( ".*shape:.*" ) if self . dummy_data_use else re . compile ( "^\s+batch_size:.*" ) batch_size_cnt = 2 if self . test_mode == "train_throughput" or self . test_mode == "scal_test" : if model not in self . train_bkm_batch_size or self . test_mode == "train_throughput" and self . cpu_model not in self . train_bkm_batch_size [ model ] : logging . exception ( "Can't find batch size of topology {} and cpu model {} within batch size table" . format ( model , self . cpu_model ) ) new_batch_size = self . train_bkm_batch_size [ model ] if self . test_mode == "scal_test" else self . train_bkm_batch_size [ model ] [ self . cpu_model ] else : if model not in self . inf_bkm_batch_size or self . cpu_model not in self . inf_bkm_batch_size [ model ] : logging . exception ( "Can't find batch size of topology {} and cpu model {} within batch size table" . format ( model , self . cpu_model ) ) new_batch_size = self . inf_bkm_batch_size [ model ] [ self . cpu_model ] if self . test_mode == "inf_latency" : new_batch_size = "1" with open ( src_model_file , 'r' ) as src_f , open ( dst_model_file , 'w' ) as dst_f : cnt = 0 for line in src_f . readlines ( ) : if re . match ( batch_size_pattern , line ) and cnt < batch_size_cnt : #change batch size line = re . sub ( "[0-9]+" , new_batch_size , line , count = 1 ) cnt += 1 dst_f . write ( line ) return dst_model_file