Skip to content

Instantly share code, notes, and snippets.

@LinXiLuo
LinXiLuo / tensorflow_rename_variables.py
Created April 29, 2019 05:53 — forked from fvisin/tensorflow_rename_variables.py
Small python script to rename variables in a TensorFlow checkpoint
# Adapted from https://gist.github.com/batzner/7c24802dd9c5e15870b4b56e22135c96
import getopt
import sys
import tensorflow as tf
usage_str = ('python tensorflow_rename_variables.py '
'--checkpoint_dir=path/to/dir/ --replace_from=substr '
'--replace_to=substr --add_prefix=abc --dry_run')
find_usage_str = ('python tensorflow_rename_variables.py '
@LinXiLuo
LinXiLuo / tensorflow_rename_variables.py
Created March 15, 2019 09:22 — forked from batzner/tensorflow_rename_variables.py
Small python script to rename variables in a TensorFlow checkpoint
import sys, getopt
import tensorflow as tf
usage_str = 'python tensorflow_rename_variables.py --checkpoint_dir=path/to/dir/ ' \
'--replace_from=substr --replace_to=substr --add_prefix=abc --dry_run'
def rename(checkpoint_dir, replace_from, replace_to, add_prefix, dry_run):
checkpoint = tf.train.get_checkpoint_state(checkpoint_dir)