删除dropout图层之前的图形定义如下所示:
fc6/BiasAdd : BiasAdd ( [u'fc6/Conv2D', u'fc6/biases/read'] )
fc6/Relu : Relu ( [u'fc6/BiasAdd'] )
dropout/keep_prob : Const ( [] )
dropout/Shape : Shape ( [u'fc6/Relu'] )
dropout/random_uniform/min : Const ( [] )
dropout/random_uniform/max : Const ( [] )
dropout/random_uniform/RandomUniform : RandomUniform ( [u'dropout/Shape'] )
dropout/random_uniform/sub : Sub ( [u'dropout/random_uniform/max', u'dropout/random_uniform/min'] )
dropout/random_uniform/mul : Mul ( [u'dropout/random_uniform/RandomUniform', u'dropout/random_uniform/sub'] )
dropout/random_uniform : Add ( [u'dropout/random_uniform/mul', u'dropout/random_uniform/min'] )
dropout/add : Add ( [u'dropout/keep_prob', u'dropout/random_uniform'] )
dropout/Floor : Floor ( [u'dropout/add'] )
dropout/Inv : Inv ( [u'dropout/keep_prob'] )
dropout/mul : Mul ( [u'fc6/Relu', u'dropout/Inv'] )
dropout/mul_1 : Mul ( [u'dropout/mul', u'dropout/Floor'] )
fc7/weights : Const ( [] )
fc7/weights/read : Identity ( [u'fc7/weights'] )
fc7/Conv2D : Conv2D ( [u'dropout/mul_1', u'fc7/weights/read'] )
格式为node.name : node.type node.input
删除丢失图层后,我必须找出如何更改特定图层的输入张量名称。删除丢失图层后,图形如下所示:
fc6/BiasAdd : BiasAdd ( [u'fc6/Conv2D', u'fc6/biases/read'] )
fc6/Relu : Relu ( [u'fc6/BiasAdd'] )
fc7/weights : Const ( [] )
fc7/weights/read : Identity ( [u'fc7/weights'] )
fc7/Conv2D : Conv2D ( [u'dropout/mul_1', u'fc7/weights/read'] )
但是,您可以看到fc7/Conv2D
操作仍然期望dropout/mul_1
作为输入。因此,我收到了这个错误:
ValueError:graph_def在节点u&f; fc7 / Conv2D'上无效:输入张量' dropout / mul_1:0'在graph_def中找不到..
我想将节点的预期输入张量名称 - 操作更改为fc6/BiasAdd
,以使网络有效。有没有办法做到这一点?
答案 0 :(得分:2)
没有直截了当的做法。通常,可以使用新操作来扩充计算图,但是不能修改现有节点。您可以遵循三种可能的路径:
keep_prob
或1(例如使用tf.placeholder_with_default
)。你仍然会有一些小的开销(我想,我不知道辍学的实现是否以1的概率绕过操作),但它可能是不明显的。tf.Graph
对象中制作图形的副本,然后将第一个会话中的变量值复制到新的会话中(例如使用load()
) tf.contrib.graph_editor
为此目的实现了许多操作。在您的情况下,您可能正在寻找类似tf.contrib.graph_editor.swap_inputs
的内容。这里的缺点是必须完成这些操作"离线",即没有使用图形的活动会话。这意味着原则上不会保存变量值。您可以checkpoint the model,手动将变量值保存到NumPy阵列,并在修改图形后恢复它们,或者,如果您已经完成培训并且只打算使用您的模型进行推理,您还可以freeze the graph 。无论如何,你必须要照顾它。