A gist for the problem is available here: https://gist.github.com/sankhaMukherjee/97c212072385ee36ebd8bfab9a801794
Essentially, I am trying to generate a generalized class that can be used as boilerplate for my tensor flow projects. The gist provided is the most trivial example that I was able to come up with. I understand that this has to do with namespaces, but am not sure how I can resolve this problem.
I have a class Test
with the following member functions:
__init__(self, inpShape, outShape, layers, activations)
saveModel(self, sess)
restoreModel(self, sess, restorePoint)
fit(self, X, y, Niter=101, restorePoint=None)
predict(self, X, restorePoint=None)
The functions themselves are trivial, and can be looked up within the gist provided. Now, given this class, we can try to test it to see how it does:
X = np.random.random((10000, 2))
y = (2*X[:, 0] + 3*X[:, 1]).reshape(-1, 1)
inpShape = (None, 2)
outShape = (None, 1)
layers = [7, 1]
activations = [tf.sigmoid, None]
t = Test(inpShape, outShape, layers, activations)
t.fit(X, y, 10000)
yHat = t.predict(X, restorePoint=t.restorePoints[-1])
plt.plot(yHat, y, '.', label='original')
This is all fine!
Now we want to create another instance of the same class, and restore a model saved from here. It is here that all hell breaks loose. Lets update the above to incorporate that:
X = np.random.random((10000, 2))
y = (2*X[:, 0] + 3*X[:, 1]).reshape(-1, 1)
inpShape = (None, 2)
outShape = (None, 1)
layers = [7, 1]
activations = [tf.sigmoid, None]
t = Test(inpShape, outShape, layers, activations)
t.fit(X, y, 10000)
yHat = t.predict(X, restorePoint=t.restorePoints[-1])
plt.plot(yHat, y, '.', label='original')
if True: # In the gist, turn this to True for seeing the problem
t1 = Test(inpShape, outShape, layers, activations)
yHat1 = t1.predict(X, restorePoint=t.restorePoints[-1])
plt.plot(yHat1, y, '.', label='copied')
It turns out, we can no longer do this. It will totally mess up everything with a totally new graph alongside the old one. Is it now possible to create a new instance of the class that copies the old graph, and not create a totally new instance of the old graph?