0

I restore a saved parameters of a model in tensorflow. I want test difference configure for my model with different layer and different parameters size.

for example if one of my parameters that I saved be like this: W_conv1 = weight_variable([7 , 7, 1, 64])

if I restore this, it works; but I want change my parameter like this : W_conv1 = weight_variable([5 , 5, 1, 64]) or W_conv1 = weight_variable([5 , 5, 1, 50]) or W_conv1 = weight_variable([9 , 9, 1, 80]) or ... .

Now I want used my saved checkpoint for restore in new config. If the size of each dimension of parameters changed it randomly initialized from my saved parameter and remind places initialize randomly.

Is it possible in tensorflow for doing this?

4

1 回答 1

0

TensorFlow 提供运算符来获取现有变量的切片 ( tf.slice),还提供运算符来为现有变量 ( ) 分配值(可能是切片tf.assign)。因此,您可以通过以下步骤实现您想要的:

  • 从检查点恢复旧变量
  • 创建不同形状的新变量,随机初始化
  • 将旧变量的相关部分分配给新变量

例如,如果您的旧变量具有形状[7, 7, 1, 64]并且您的新变量具有形状[5, 5, 1, 64],那么这里有一个对旧变量进行切片并分配给新变量的方法:

# old_variable has the shape [7, 7, 1, 64]
new_variable = tf.Variable(np.random.rand(5, 5, 1, 64))
assign_new_var = tf.assign(new_variable, old_variable([:5, :5, :, :]))
于 2016-07-05T15:00:30.187 回答