Skip to content

Commit

Permalink
Update paddle_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
nepeplwu committed Mar 13, 2020
1 parent 9adff31 commit 223cd2f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions paddlehub/common/paddle_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,19 @@ def rename_var(block, old_name, new_name):
block._rename_var(old_name, new_name)


def add_vars_prefix(program, prefix, vars=None):
def add_vars_prefix(program, prefix, vars=None, excludes=None):
block = program.global_block()
vars = list(vars) if vars else list(block.vars.keys())
vars = [var for var in vars if var not in excludes] if excludes else vars
for var in vars:
rename_var(block, var, prefix + var)


def remove_vars_prefix(program, prefix, vars=None):
def remove_vars_prefix(program, prefix, vars=None, excludes=None):
block = program.global_block()
vars = [var for var in vars if var.startswith(prefix)] if vars else [
var for var in block.vars.keys() if var.startswith(prefix)
]
vars = [var for var in vars if var not in excludes] if excludes else vars
for var in vars:
rename_var(block, var, var.replace(prefix, "", 1))

0 comments on commit 223cd2f

Please sign in to comment.