zoukankan      html  css  js  c++  java
  • tensorflow定义神经网络损失函数MSE

    import numpy as np
    import tensorflow as tf
    
    y_pred = np.array([[1],
                       [2],
                       [3]],dtype=np.float32)
    y_real = np.array([[1],
                       [1],
                       [1]])
        
    bias = np.array([1,2,3,4],dtype=np.float32)
    
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        Input = tf.reduce_mean(tf.square(y_pred-y_real))
    # =============================================================================
    #     tf.square(y_pred-y_real)
    #     [[0]
    #      [1]
    #      [4]]
    # =============================================================================   
        result = sess.run(Input) 
        print(result)
    #返回1.6666666666666667,如果不加轴的话,返回的是一个数
  • 相关阅读:
    NACBD
    周总结7
    周总结6
    团队题目——TD课程通
    移动端疫情展示
    周总结5
    每周总结4
    每周总结3
    每周总结2
    求最大子数组
  • 原文地址:https://www.cnblogs.com/wzdLY/p/9749068.html
Copyright © 2011-2022 走看看