Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 跨类的张量流命名空间_Python_Tensorflow_Graph_Namespaces - Fatal编程技术网

Python 跨类的张量流命名空间

Python 跨类的张量流命名空间,python,tensorflow,graph,namespaces,Python,Tensorflow,Graph,Namespaces,此处提供了该问题的要点: 本质上,我正在尝试生成一个通用类,它可以用作我的张量流项目的样板。提供的要点是我能想到的最微不足道的例子。我知道这与名称空间有关,但不确定如何解决此问题 我有一个类Test,具有以下成员函数: \uuuuu初始(自我、inpShape、outShape、层、激活) saveModel(self,sess) restoreModel(self、sess、restorePoint) fit(self,X,y,Niter=101,restorePoint=None) pred

此处提供了该问题的要点:

本质上,我正在尝试生成一个通用类,它可以用作我的张量流项目的样板。提供的要点是我能想到的最微不足道的例子。我知道这与名称空间有关,但不确定如何解决此问题

我有一个类
Test
,具有以下成员函数:

  • \uuuuu初始(自我、inpShape、outShape、层、激活)
  • saveModel(self,sess)
  • restoreModel(self、sess、restorePoint)
  • fit(self,X,y,Niter=101,restorePoint=None)
  • predict(self,X,restorePoint=None)
  • 函数本身很简单,可以在提供的要点中查找。现在,给定这个类,我们可以尝试测试它,看看它是如何工作的:

    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')
    
    这一切都很好

    现在我们要创建同一类的另一个实例,并从这里恢复保存的模型。就是在这里,所有的地狱都开始了。让我们更新以上内容以合并:

    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')
    

    事实证明,我们不能再这样做了。它会把一切都搞糟,在旧的图形旁边放一个全新的图形。现在是否可以创建复制旧图形的类的新实例,而不创建旧图形的全新实例?

    您的模型还原不正确,我已经回答了一个类似的问题:谢谢Vijay!我将尝试一下TF名称空间与python的不同,您需要使用一些名称空间功能。