Reputation: 91
I have the following code in a file called task.py
:
def train():
saver_refine = tf.train.Saver(coarse_refine_params)
saver_refine.restore(sess, refine_ckpt.model_checkpoint_path)
I import from task.py
:
from task import train
train.saver_refine.restore(sess, refine_ckpt.model_checkpoint_path)
I try to do the above function.
Error:AttributeError: 'function' object has no attribute 'saver_refine'
What could be going wrong here?
Upvotes: 1
Views: 20698
Reputation: 214
This is possible but usually not useful.
def func():
pass
func.saver_refine = 1
print(func.saver_refine)
Accessing local variables from the outside is not possible, they only exist in the namespace of the function while it runs, and they are lost once the function exits.
Upvotes: 3