参数无效:NodeDef提到attr'Tshape'不在Op中

时间:2016-11-12 23:36:13

标签: android python java-native-interface tensorflow

尝试使用Invalid argument: NodeDef mentions attr 'Tshape' not in Op<name=Reshape; signature=tensor:T, shape:int32 -> output:T; attr=T:type>; NodeDef: Y_GroundTruth = Reshape[T=DT_FLOAT, Tshape=DT_INT32](LOut_Add, Y_GroundTruth/shape)在Android上加载文件时收到错误tensorflow::Status s = session->Create(graph_def);

有类似问题的人提到升级到Tensorflow 0.9.0rc0修复了他们的问题。但是,我已经在我的jni-build中使用了最新的Tensorflow构建。

这可能是生成protobuf文件时声明的变量的问题吗?

def reg_perceptron(t, weights, biases):
    t = tf.nn.relu(tf.add(tf.matmul(t, weights['h1']), biases['b1']), name = "layer_1")
    t = tf.nn.sigmoid(tf.add(tf.matmul(t, weights['h2']), biases['b2']), name = "layer_2")
    t = tf.add(tf.matmul(t, weights['hOut'], name="LOut_MatMul"), biases['bOut'], name="LOut_Add")

    return tf.reshape(t, [-1], name="Y_GroundTruth")

g = tf.Graph()
with g.as_default():
   ...
   rg_weights = {
    'h1': vs.get_variable("weights0", [n_input, n_hidden_1], initializer=tf.contrib.layers.xavier_initializer()),
    'h2': vs.get_variable("weights1", [n_hidden_1, n_hidden_2], initializer=tf.contrib.layers.xavier_initializer()),
    'hOut': vs.get_variable("weightsOut", [n_hidden_2, 1], initializer=tf.contrib.layers.xavier_initializer())
    }


    rg_biases = {
    'b1': vs.get_variable("bias0", [n_hidden_1], initializer=init_ops.constant_initializer(bias_start)),
    'b2': vs.get_variable("bias1", [n_hidden_2], initializer=init_ops.constant_initializer(bias_start)),
    'bOut': vs.get_variable("biasOut", [1], initializer=init_ops.constant_initializer(bias_start))
    }

    pred = reg_perceptron(_x, rg_weights, rg_biases)
    ...
...

g_2 = tf.Graph()
with g_2.as_default():
    ...
    rg_weights_2 = {
    'h1': vs.get_variable("weights0", [n_input, n_hidden_1], initializer=tf.contrib.layers.xavier_initializer()),
    'h2': vs.get_variable("weights1", [n_hidden_1, n_hidden_2], initializer=tf.contrib.layers.xavier_initializer()),
    'hOut': vs.get_variable("weightsOut", [n_hidden_2, 1], initializer=tf.contrib.layers.xavier_initializer())
    }

    rg_biases_2 = {
    'b1': vs.get_variable("bias0", [n_hidden_1], initializer=init_ops.constant_initializer(bias_start)),
    'b2': vs.get_variable("bias1", [n_hidden_2], initializer=init_ops.constant_initializer(bias_start)),
    'bOut': vs.get_variable("biasOut", [1], initializer=init_ops.constant_initializer(bias_start))
    }

    pred_2 = reg_perceptron(_x_2, rg_weights_2, rg_biases_2)
    ...

为了阻止帖子过于混乱,我上传了我的代码以生成.PB文件和我的模型以在Pastebin上创建模型。

PBFileGeneration

Model

0 个答案:

没有答案