LouisEchard / ML_MiniProjects

Personal db
0 stars 0 forks source link

Strange initialization problem #30

Closed LouisEchard closed 6 years ago

LouisEchard commented 6 years ago

If I do :

with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess:
    new_saver = tf.train.import_meta_graph(pathsToVariables + 'Weights/weights.meta')
    new_saver.restore(sess, pathsToVariables + 'Weights/weights')

    print(sess.run(tf.get_default_graph().get_tensor_by_name("w1:0")))

I get the right results.

If I do :

with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess:

    new_saver = tf.train.import_meta_graph(pathsToVariables + 'Weights/weights.meta')
    new_saver.restore(sess, pathsToVariables + 'Weights/weights')

    weights = {
        '1': tf.Variable(tf.get_default_graph().get_tensor_by_name("w1:0"), name='w1', trainable=False)
    }
    sess.run(tf.global_variables_initializer())
    print(sess.run(weights['1']))

I get random results. Why is this behavior occuring ?

LouisEchard commented 6 years ago

On my laptop (Tensorflow CPU), the initialized weight do sometimes give me the right solution. But only from time to time. I am running 1.4.1 CPU on my laptop and 1.7 GPU on my other computer.

LouisEchard commented 6 years ago

One way to bypass this issue, is to only optimize given variables with minimize(var_list), but it's not as nice.

LouisEchard commented 6 years ago

Solved by doing :

weights = {
        '1': tf.Variable(sess.run(tf.get_default_graph().get_tensor_by_name("w1:0")), name='w1', trainable=False)
    }