(old_args, export_dir)
Edit file path argument in pbtxt file.
  :param old_args: Old file paths need to be copied and edited.
  :param export_dir: Directory of the saved model.
Edit file path argument in pbtxt file.
  :param old_args: Old file paths need to be copied and edited.
  :param export_dir: Directory of the saved model.
Edit file path argument in pbtxt file . : param old_args : Old file paths need to be copied and edited . : param export_dir : Directory of the saved model .
def edit_pb_txt(old_args, export_dir):
  """
  Edit file path argument in pbtxt file.
  :param old_args: Old file paths need to be copied and edited.
  :param export_dir: Directory of the saved model.
  """
  assets_extra_dir = os.path.join(export_dir, "./assets.extra")
  if not os.path.exists(assets_extra_dir):
    os.makedirs(assets_extra_dir)

  new_args = []
  for one_old in old_args:
    if not os.path.exists(one_old):
      raise ValueError("{} do not exists!".format(one_old))
    one_new = os.path.join(assets_extra_dir, os.path.basename(one_old))
    new_args.append(one_new)
    logging.info("Copy file: {} to: {}".format(one_old, one_new))
    gfile.Copy(one_old, one_new, overwrite=True)

  pbtxt_file = os.path.join(export_dir, "saved_model.pbtxt")
  tmp_file = pbtxt_file + ".tmp"
  logging.info("Editing pbtxt file: {}".format(pbtxt_file))
  with open(pbtxt_file, "rt") as fin, open(tmp_file, "wt") as fout:
    for line in fin:
      for one_old, one_new in zip(old_args, new_args):
        line = line.replace(one_old, one_new)
      fout.write(line)
  gfile.Copy(tmp_file, pbtxt_file, overwrite=True)
  gfile.Remove(tmp_file)
def edit_pb_txt ( old_args , export_dir ) : assets_extra_dir = os . path . join ( export_dir , "./assets.extra" ) if not os . path . exists ( assets_extra_dir ) : os . makedirs ( assets_extra_dir ) new_args = [ ] for one_old in old_args : if not os . path . exists ( one_old ) : raise ValueError ( "{} do not exists!" . format ( one_old ) ) one_new = os . path . join ( assets_extra_dir , os . path . basename ( one_old ) ) new_args . append ( one_new ) logging . info ( "Copy file: {} to: {}" . format ( one_old , one_new ) ) gfile . Copy ( one_old , one_new , overwrite = True ) pbtxt_file = os . path . join ( export_dir , "saved_model.pbtxt" ) tmp_file = pbtxt_file + ".tmp" logging . info ( "Editing pbtxt file: {}" . format ( pbtxt_file ) ) with open ( pbtxt_file , "rt" ) as fin , open ( tmp_file , "wt" ) as fout : for line in fin : for one_old , one_new in zip ( old_args , new_args ) : line = line . replace ( one_old , one_new ) fout . write ( line ) gfile . Copy ( tmp_file , pbtxt_file , overwrite = True ) gfile . Remove ( tmp_file )