0

I want to load checkpoint file, change shapes of some variables ((1,1,1024,55) -> (1,1,1024,60)) and then save checkpoint again

What I've done:

1. I've loaded checkpoint

saver = tf.train.import_meta_graph(meta)
saver.restore(sess, ckpt
  1. Tried to use tf.assign():

    for var in tf.global_variables(): if var.name == "22-convolutional/biases:0": assign = tf.assign(var, a, validate_shape=False) sess.run(assign)

And then, when I am trying to execute

sess.run(tf.global_variables_initializer())

I have an error

Assign requires shapes of both tensors to match. lhs shape= [1,1,1024,60] rhs shape= [1,1,1024,55] [[Node: 22-convolutional/kernel/Adam_1/Assign = Assign[T=DT_FLOAT, _class=["loc:@22-convolutional/kernel"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/cpu:0"](22-convolutional/kernel/Adam_1, zeros_51)]]

Is there any ideas of what to try?

Thank you!

Dmitry
  • 91
  • 2
  • 7
  • and **what** is expected result? What happens to missing 5 values? – lejlot Aug 25 '17 at 20:42
  • New tensor after assigning may be full with zeros. Also, it won't initiate any computational problems after changing shape of necessary for me variables, shapes will match well – Dmitry Aug 26 '17 at 11:17

1 Answers1

1

You cannot change the shape of a variable. The shape is defined on creation and every value that you assign to it must have that shape. If the new value is always smaller than the original one, you can consider doing a slice assignment, if that's helpful for you. Or you can use a new variable, or something else. But there is no "trick" that allows you to actually change the shape.

jdehesa
  • 58,456
  • 7
  • 77
  • 121
  • Also I've tried the next approach: I've created new variable `a` with the name of old_var , and just written `old_var = a`. But after assigning, `a` has a name of old_var + postfix __1_ – Dmitry Aug 25 '17 at 16:52
  • @Dmitry Yes, you cannot "overwrite" a variable with another one, or anything like that, once you make it it's there forever an no other op can use the same name. You can use a new, different variable, but it will not be automatically related to the previous one anyhow. Also doing `old_var = a` will just replace the reference held by `old_var`, but the variable will still exist in the graph. – jdehesa Aug 26 '17 at 16:43