ValueError: Output tensors to a Model must be the output of a TensorFlow `Layer`

前端 未结 2 1302
小鲜肉
小鲜肉 2020-12-09 16:17

I\'m building a model in Keras using some tensorflow function (reduce_sum and l2_normalize) in the last layer while encountered this problem. I have searched for a solution

相关标签:
2条回答
  • 2020-12-09 16:59

    I had this issue because I was adding 2 tensors as x1+x2 somewhere in my model instead of using Add()([x1,x2]).

    That solved the problem.

    0 讨论(0)
  • 2020-12-09 17:16

    I have found a way to work around to solve the problem. For anyone who encounters the same issue, you can use the Lambda layer to wrap your tensorflow operations, this is what I did:

    from tensorflow.python.keras.layers import Lambda;
    
    def norm(fc2):
    
        fc2_norm = K.l2_normalize(fc2, axis = 3);
        illum_est = tf.reduce_sum(fc2_norm, axis = (1, 2));
        illum_est = K.l2_normalize(illum_est);
    
        return illum_est;
    
    illum_est = Lambda(norm)(fc2);
    
    0 讨论(0)
提交回复
热议问题