Code Monkey home page Code Monkey logo

Comments (3)

joaoluiscarreira avatar joaoluiscarreira commented on September 24, 2024

Hi,

this is old tensorflow code (2017), but hopefully still helpful:

def assign_from_checkpoint_2d_to_3d_scale(model_path, var_list):
"""Creates an operation to assign specific variables from a checkpoint.

Args:
model_path: The full path to the model checkpoint. To get latest checkpoint
use model_path = tf.train.latest_checkpoint(checkpoint_dir)
var_list: A list of Variable objects or a dictionary mapping names in the
checkpoint to the corresponding variables to initialize. If empty or
None, it would return no_op(), None.

Returns:
the restore_op and the feed_dict that need to be run to restore var_list.

Raises:
ValueError: If the checkpoint specified at model_path is missing one of
the variables in var_list.
"""

reader = pywrap_tensorflow.NewCheckpointReader(model_path)

if isinstance(var_list, (tuple, list)):
var_list = {var.op.name: var for var in var_list}

feed_dict = {}
assign_ops = []

for checkpoint_var_name in var_list:
var = var_list[checkpoint_var_name]
if not reader.has_tensor(checkpoint_var_name):
raise ValueError(
'Checkpoint is missing variable [%s]' % checkpoint_var_name)

var_value = reader.get_tensor(checkpoint_var_name)
placeholder_name = 'placeholder/' + var.op.name
placeholder_value = tf.placeholder(
    dtype=var.dtype.base_dtype,
    shape=var.get_shape(),
    name=placeholder_name)
assign_ops.append(var.assign(placeholder_value))

if var.get_shape() != var_value.shape:
  n = var_value.shape[0]
  feed_dict[placeholder_value] = np.tile(np.expand_dims(var_value/n,0), [n,1,1,1,1])
else:
  feed_dict[placeholder_value] = var_value.reshape(var.get_shape())

assign_op = tf.group(*assign_ops)
return assign_op, feed_dict

from kinetics-i3d.

emergencyd avatar emergencyd commented on September 24, 2024

Thank you very much!
Is there bn/gn parameter in the pretrained 2D model? if so, do we need to ignore it or also load it to the I3D model?

from kinetics-i3d.

joaoluiscarreira avatar joaoluiscarreira commented on September 24, 2024

from kinetics-i3d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.